-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adagrams #20
base: master
Are you sure you want to change the base?
adagrams #20
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! I love this, very clear!
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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yum, this is also great!
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerable
mixin? If so, where and why was it helpful?