- 
                Notifications
    You must be signed in to change notification settings 
- Fork 29
Sockets - Bita and Maria #25
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
4475608
              2cb5ad9
              1027f0b
              c38c18d
              a9d3f24
              f5c705a
              a8ca937
              c3b8009
              f69e7f5
              f6888d1
              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,12 @@ | ||
| # wirte a method with no parameters | ||
| letters = [] | ||
| 9.times do | ||
| letters.push("A") | ||
| end | ||
| puts letters | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| def draw_letters | ||
| pool_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] | ||
|  | ||
| letters = pool_letters | ||
| letters.shuffle | ||
| letters_in_hand = letters.sample(10) | ||
| letters_in_hand | ||
| end | ||
|  | ||
| def uses_available_letters?(input, letters_in_hand) | ||
| input.each_char do |letter| | ||
| index = letters_in_hand.index(letter.upcase) | ||
| if index.nil? | ||
| return false | ||
| else | ||
| letters_in_hand.delete_at(index) | ||
| 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. Because this deletes letters as it finds them if the user inputs an invalid word the letters it does use will be deleted. For example:  | ||
| end | ||
| end | ||
| true | ||
| end | ||
|  | ||
| def score_word(word) | ||
| score_value = { A: 1, B: 3, C: 3, D: 2, E: 1, F: 4, G: 2, H: 4, I: 1, J: 8, K: 5, L: 1, M: 3, N: 1, O: 1, P: 3, Q: 10, R: 1, S: 1, T: 1, U: 1, V: 4, W: 4, X: 8, Y: 4, Z: 10 } | ||
| scored = 0 | ||
| word = word.upcase | ||
| word.each_char do |letter| | ||
| scored += score_value[letter.to_sym].to_i | ||
| end | ||
| scored += 8 if word.length > 6 | ||
| scored | ||
| end | ||
|  | ||
| def highest_score_from(words) | ||
| scores = [] | ||
| words.each do |word| | ||
| score = score_word(word.upcase) | ||
| scores << score | ||
| end | ||
|  | ||
| scores_hash = Hash[words.zip scores] | ||
| puts "scores_hash #{scores_hash}" | ||
| 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 the future you should remove debugging  Leaving the   | ||
| winner_score = scores_hash.select { |_key, value| value == scores_hash.values.max } | ||
| puts "winner_score #{winner_score}" | ||
| puts "winner_score.length #{winner_score.length}" | ||
| 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. Remove debugging  | ||
|  | ||
| long_words = [] | ||
| winner_score.each do |key, _value| | ||
| if key.length == 10 | ||
| long_words << key | ||
| end | ||
| end | ||
|  | ||
| winner = "" | ||
| if long_words.length == 1 | ||
| winner = long_words[0] | ||
| elsif long_words.length > 1 | ||
| winner = long_words[0] | ||
| else | ||
| short_words = winner_score.min_by { |key, _value| key.length } | ||
| 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. Try to use more descriptive names. For example in this case you could do something like: short_words = winner_score.min_by { |word, _score| word.length } | ||
| winner = short_words[0] | ||
| end | ||
|  | ||
| winner_values = {} | ||
| winner_values[:word] = winner | ||
| winner_values[:score] = scores.max | ||
| winner_values | ||
| end | ||
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.
In the future make sure to clean up files you aren't using.