-
Couldn't load subscription status.
- Fork 29
Ports - Heather & Laneia #12
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| require "awesome_print" | ||
|
|
||
| def draw_letters | ||
| avail_letters = %w[A A A A A A A A A B B C C D D D D E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S S S T T T T T T U U U U V V W W X Y Y Z] | ||
| avail_letters.sample(10) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, your code takes advantage of Ruby's implicit |
||
| end | ||
|
|
||
| sample = draw_letters | ||
| # print sample | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this code will not be used when running tests, feel free to delete these lines before project submission |
||
|
|
||
| def uses_available_letters?(input, letters_in_hand) | ||
| letters_in_hand = letters_in_hand.clone | ||
| input = input.upcase | ||
| input.each_char.all? do |char| | ||
| if letters_in_hand.include?(char) | ||
| letters_in_hand.delete_at(letters_in_hand.index(char)) | ||
| true | ||
| else | ||
| false | ||
| end | ||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VERY interesting and good job of implementing your own I have an example of maybe what I would do: is_valid = input.each_char.all? do |char|
if letters_in_hand.include?(char)
letters_in_hand.delete_at(letters_in_hand.index(char))
true
else
false
end
end
return is_valid |
||
| end | ||
|
|
||
| def score_word(word) | ||
| score = [] | ||
| score_chart = [%w[A E I O U L N R S T], %w[D G], %w[B C M P], %w[F H V W Y], %w[K]] | ||
| word = word.upcase | ||
|
|
||
| score_chart.each_with_index do |letter_bank, letter_value| | ||
| word.each_char do |char| | ||
| if letter_bank.include?(char) | ||
| score << (letter_value + 1) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha! Interesting relationship between the index of the |
||
| end | ||
| end | ||
| end | ||
|
|
||
| word.each_char do |char| | ||
| if ["J", "X"].include?(char) | ||
| score << 8 | ||
| elsif ["Q", "Z"].include?(char) | ||
| score << 10 | ||
| end | ||
| end | ||
|
|
||
| if word.length > 6 | ||
| score << 8 | ||
| end | ||
|
|
||
| return score.sum | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's really fascinating that you all did an array of scores and then summed it in the end! I think most people would have opted to just add them, but I think this is also valid and interesting and cool and is very compatible with thinking like a programmer :D |
||
| end | ||
|
|
||
| def highest_score_from(words) | ||
| scored_words = [] | ||
|
|
||
| words.each do |played_word| | ||
| played_word = played_word.upcase | ||
| scored_words << | ||
| { | ||
| each_word: played_word, each_score: score_word(played_word), | ||
| } | ||
| end | ||
|
|
||
| high_score = scored_words.max_by { |point| | ||
| point[:each_score] | ||
| }[:each_score] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic use of |
||
|
|
||
| highest_scored_words = scored_words.select { |semi_finalist| | ||
| semi_finalist[:each_score] == high_score | ||
| }.map { |semi_finalist| | ||
| semi_finalist[:each_word] | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that using |
||
|
|
||
| if highest_scored_words.length == 1 | ||
| return ultimate_winner = {word: highest_scored_words[0], score: high_score} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the |
||
| elsif highest_scored_words.length > 1 | ||
| winner = highest_scored_words.find { |ten| ten.length == 10 } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! This works with knowing that |
||
| return {word: winner, score: high_score} if winner | ||
| end | ||
| return {word: highest_scored_words.min_by { |highest| highest.length }, score: high_score} | ||
| end | ||
|
|
||
| def is_in_english_dict?(user_input_word) | ||
| require "csv" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll want to put all |
||
| dictionary_array = [] | ||
| CSV.foreach("assets/dictionary-english.csv") do |row| | ||
| dictionary_array << row | ||
| end | ||
| dictionary_array.flatten! | ||
| return dictionary_array.include?(user_input_word) ? true : false | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider why this is the same thing as above: |
||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work on this optional! :D ... Where are the tests to verify that it works? ;) |
||
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.
Yes! I love this syntax! This implementation is so short! :) Fantastic.