Conversation
… 'word', score: integer)
AdagramsWhat We're Looking For
|
| def draw_letters | ||
| letter_bank = Array.new | ||
| 10.times do | ||
| random_letter_picked = LETTERS_TO_QUANTITY.keys.sample |
There was a problem hiding this comment.
So, you have a probability problem here. When you sample from the keys, the odds are not weighted by the number of each tile in the letter_bank. Your results give a 1/26 chance to draw any letter, but that's not accurate is it?
|
|
||
| def uses_available_letters?(user_input_word, letter_bank) | ||
| array_of_input_letters = user_input_word.split('') | ||
| letter_bank_hash = letters_to_hash(letter_bank) |
There was a problem hiding this comment.
Is there any reason you couldn't have done this with 2 arrays?
| user_input_letters_hash = letters_to_hash(array_of_input_letters) | ||
| output = true | ||
| user_input_letters_hash.each do |key,value| | ||
| if !letter_bank_hash.keys.include?(key) # look at looping of outputs, see what happens if use |
There was a problem hiding this comment.
As soon as one of these is false, do you need to check the whole hash still?
| user_input_word_hash.each do |word_key, word_value| | ||
| SCORE_TO_LETTERS.each do |score_key, score_value| | ||
| if score_value.include?(word_key) | ||
| score = score_key*word_value |
There was a problem hiding this comment.
It took me a minute to see why this works. Again, using a hash here is actually more work for you, and hindering clarity.
| end | ||
| end | ||
| end | ||
| total_score = array_of_letter_scores.reduce(:+) |
There was a problem hiding this comment.
reduce is hiding a loop from you, though you could have used reduce to solve this problem by replacing an earlier .each.
|
|
||
| def highest_score_from(played_words) | ||
| collection_of_played_words_and_scores = []#array of hashes | ||
| played_words.each do |word| |
| played_word_to_score[:score] = score_word(word) | ||
| collection_of_played_words_and_scores.push(played_word_to_score) | ||
| end | ||
| top_score = collection_of_played_words_and_scores.reduce(0){ |memo, h| h[:score] > memo ? h[:score] : memo } # ==> {score: n} |
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerablemixin? If so, where and why was it helpful?