-
Notifications
You must be signed in to change notification settings - Fork 29
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
Sockets - Chantal & Tatiana #24
base: master
Are you sure you want to change the base?
Changes from all commits
2585f7b
f54d378
789a06d
a9e4e6b
12313a8
ee055d7
d190bc3
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,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Local File", | ||
"type": "Ruby", | ||
"request": "launch", | ||
"cwd": "${workspaceRoot}", | ||
"program": "${file}" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
require 'awesome_print' | ||
require 'pry' | ||
|
||
def draw_letters | ||
letters = [ | ||
"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" | ||
] | ||
drawn_letters = letters.sample(10) | ||
return drawn_letters | ||
end | ||
|
||
|
||
draw_letters | ||
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 don't need to call |
||
|
||
def uses_available_letters?(input, letters_in_hand) | ||
input.each_char do |letter| | ||
index = letters_in_hand.index(letter) | ||
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. When you call hand = ['A', 'B', 'C']
word = 'ABC'
puts uses_available_letters?(word, hand)
# => true
puts uses_available_letters?(word, hand)
# => false How might you address this problem? |
||
end | ||
end | ||
return true | ||
end | ||
|
||
def score_word (word) | ||
score = 0 | ||
word.upcase.each_char do |letter| | ||
|
||
case letter | ||
when "A", 'E', 'I', 'O', 'U', 'L', 'R', 'N', 'S', 'T' | ||
score += 1 | ||
when 'D', 'G' | ||
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. While this 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 |
||
score += 2 | ||
when 'B', 'C', 'M', 'P' | ||
score += 3 | ||
when 'F', 'H', 'V', 'W', 'Y' | ||
score += 4 | ||
when 'K' | ||
score += 5 | ||
when 'J', 'X' | ||
score += 8 | ||
when 'Q', 'Z' | ||
score += 10 | ||
end | ||
end | ||
|
||
if word.length > 6 && word.length < 11 | ||
score += 8 | ||
end | ||
|
||
return score | ||
|
||
end | ||
|
||
|
||
def highest_score_from (words) | ||
|
||
score_list = words.map do |element| | ||
{ word: element, score: score_word(element) } | ||
end | ||
|
||
find_best_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. Watch your indentation through here. Have you installed rubocop and rufo to automatically adjust your formatting? |
||
max = 0 | ||
|
||
score_list.each do |element| | ||
if element[:score] > max | ||
find_best_word = [element] | ||
max = element[:score] | ||
elsif element[:score] == max | ||
find_best_word << element | ||
end | ||
end | ||
p find_best_word | ||
winner = find_best_word.first | ||
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. Please remove debugging output (like line 100) before submitting projects. |
||
shortest = 10 | ||
|
||
find_best_word.each do |entry| | ||
if entry[:word].length == 10 | ||
return winner = entry | ||
elsif entry[:word].length < shortest | ||
winner = entry | ||
shortest = entry[:word].length | ||
end | ||
end | ||
|
||
return winner | ||
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.
This data would be a great thing to store in a constant!