-
Notifications
You must be signed in to change notification settings - Fork 29
Sockets - Hana && Nara #14
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
dbd1a33
16f1e16
b70dd10
fe83c7b
cf9a537
e78ae6a
58e4dcc
fc8a4c2
5d73196
b0afcff
f0036b5
a522553
e848c9d
40fc384
b55c355
002b764
87e7a36
0320bab
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,97 @@ | ||
| def draw_letters | ||
| letter_pool = { A: 9, B: 2, C: 2, D: 4, E: 12, F: 2, G: 3, H: 2, I: 9, J: 1, K: 1, L: 4, M: 2, N: 6, O: 8, P: 2, Q: 1, R: 6, S: 4, T: 6, U: 4, V: 2, W: 2, X: 1, Y: 2, Z: 1 } | ||
| letter_array = [] | ||
| letter_pool.each do |letter, quantity| | ||
| quantity.times do | ||
| letter_array << letter.to_s.downcase | ||
| end | ||
| end | ||
| return letter_array.sample(10) | ||
| end | ||
|
|
||
| def uses_available_letters?(input, letters_in_hand) | ||
| size = 0 | ||
| input_array = input.upcase.split(//) | ||
|
|
||
| letters_in_hand.each_with_index do |letter, index| | ||
| if input_array.include?(letter) | ||
|
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. This is really close to right. Because of the way the above loop is implemented this winds up requiring the user to use all of a given letter. If you |
||
| size += 1 | ||
| letters_in_hand.delete(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 you delete letters from the hand as you go if a user submits a mostly correct word the letters it used are deleted. For example: |
||
| end | ||
| end | ||
|
|
||
| if size == input_array.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. This works but having to keep track of |
||
| return true | ||
| else | ||
| return false | ||
| end | ||
| end | ||
|
|
||
| def score_word(word) | ||
| points = 0 | ||
| word.upcase.split(//).each do |letter| | ||
|
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. There's a handy |
||
| case letter | ||
| when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" | ||
| points += 1 | ||
| when "D", "G" | ||
| points += 2 | ||
| when "B", "C", "M", "P" | ||
| points += 3 | ||
| when "F", "H", "V", "W", "Y" | ||
| points += 4 | ||
| when "K" | ||
| points += 5 | ||
| when "J", "X" | ||
| points += 8 | ||
| when "Q", "Z" | ||
| points += 10 | ||
| end | ||
| end | ||
|
|
||
| if word.length > 6 && word.length < 11 | ||
| points += 8 | ||
| end | ||
|
|
||
| return points | ||
| end | ||
|
|
||
| def highest_score_from(words) | ||
| highest_score = Hash.new(0) | ||
|
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. Misleading variable name: |
||
|
|
||
| words.each do |word| | ||
| highest_score[word] = score_word(word) | ||
| end | ||
|
|
||
| max_words = { | ||
| word: [], | ||
| score: [], | ||
| } | ||
|
|
||
| highest_score.each do |k, v| | ||
| if v == highest_score.values.max | ||
| max_words[:word] << k | ||
| max_words[:score] = v | ||
| end | ||
| end | ||
|
|
||
| best_word = {} | ||
|
|
||
| min_length = 10 | ||
| if max_words[:word].length == 1 | ||
| best_word[:word] = max_words[:word][0] | ||
| best_word[:score] = max_words[:score] | ||
| else | ||
| max_words[:word].each do |word| | ||
| if word.length == 10 | ||
| best_word[:word] = word | ||
| best_word[:score] = max_words[:score] | ||
| return best_word | ||
| elsif word.length < min_length | ||
| min_length = word.length | ||
| best_word[:word] = word | ||
| best_word[:score] = max_words[: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. This is a clever way to find the shortest word in |
||
| end | ||
| end | ||
| end | ||
| return best_word | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| require_relative 'lib/adagrams' | ||
| require 'pry' | ||
|
|
||
| def display_welcome_message | ||
| puts "Welcome to Adagrams!" | ||
|
|
||
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.
Calling
upcaseon the user's input is a good idea, however you forgot to callupcaseon the letters inletters_in_handwhich means that if you are passed lowercase letters you won't have any matches.You could add this to fix it: