-
Notifications
You must be signed in to change notification settings - Fork 33
Leaves - Alice and Tiffany #4
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
base: master
Are you sure you want to change the base?
Conversation
require "csv" | ||
|
||
def draw_letters() | ||
letter_pool = ["A"] * 9 + ["B"] * 2 + ["C"] * 2 + ["D"] * 4 + ["E"] * 12 + ["F"] * 2 + ["G"] * 3 + ["H"] * 2 + ["I"] * 9 + ["J"] + ["K"] + ["L"] * 4 + ["M"] * 2 + ["N"] * 6 + ["O"] * 8 + ["P"] * 2 + ["Q"] + ["R"] * 6 + ["S"] * 4 + ["T"] * 6 + ["U"] * 4 + ["V"] * 2 + ["W"] * 2 + ["X"] + ["Y"] * 2 + ["Z"] |
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.
Consider using a data structure to store the letter distribution information. You can then use this data structure to create your array.
letter_counts = {"A"=>9, "B"=>2,...}
def score_word(word) | ||
word_arr = word.upcase.split("") | ||
points = 0 | ||
word_arr.each do |letter| |
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.
While this case
statement works, it means that the information about which letter has which score is locked into this piece of code, and can't easily be used elsewhere. For example, if you wanted to display the value of each letter in a hand, you would need to repeat this work.
An alternative approach would be to store the letter scores in a hash, something like this:
LETTER_SCORES = {
"A" => 1
"B" => 3,
"C" => 3,
"D" => 2,
# ...
}
Then to get the score for a letter, you can say LETTER_SCORES[letter]
.
word_score << { word: word, score: score_word(word) } | ||
end | ||
|
||
max = word_score.max_by { |element| element[:score] }[:score] |
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.
You've packed lots of logic in a few lines of elegant code. Consider adding a few comments that outline the rules for determining the winner, particularly the tiebreaker logic.
AdagramsWhat We're Looking For
I'm making a few comments on this assignment about some suggestions on how to refactor, but they are all optional ways of looking at this code again. Overall, you two have done a great job. Good work! |
Adagrams
Congratulations! You're submitting your assignment.
Comprehension Questions
Enumerable
mixin? If so, where and why was it helpful?