-
Notifications
You must be signed in to change notification settings - Fork 36
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
Sandy & Madeline #28
base: master
Are you sure you want to change the base?
Sandy & Madeline #28
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,3 @@ | ||
{ | ||
"url": "https://floobits.com/spv1/adagrams" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extern | ||
node_modules | ||
tmp | ||
vendor | ||
.idea/workspace.xml | ||
.idea/misc.xml |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,121 @@ | ||||||||||||
# wave 1 | ||||||||||||
def draw_letters | ||||||||||||
letters_array = [ | ||||||||||||
"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 = letters_array.shuffle.pop(10) | ||||||||||||
|
||||||||||||
return letters | ||||||||||||
end | ||||||||||||
|
||||||||||||
# wave 2 | ||||||||||||
puts "Enter in a word: " | ||||||||||||
input = gets.chomp.to_s | ||||||||||||
|
||||||||||||
letters_in_hand = input.split(//) | ||||||||||||
print letters_in_hand | ||||||||||||
Comment on lines
+38
to
+42
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.
Suggested change
|
||||||||||||
|
||||||||||||
def uses_available_letters?(input, letters_in_hand) | ||||||||||||
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. 👍 |
||||||||||||
check_input = input.split(//) | ||||||||||||
|
||||||||||||
my_letters_in_hand = Array.new(letters_in_hand) | ||||||||||||
|
||||||||||||
check_input.each do |letter| | ||||||||||||
letter_index = my_letters_in_hand.find_index(letter) | ||||||||||||
|
||||||||||||
if letter_index == nil | ||||||||||||
return false | ||||||||||||
end | ||||||||||||
|
||||||||||||
my_letters_in_hand.delete_at(letter_index) | ||||||||||||
end | ||||||||||||
|
||||||||||||
return true | ||||||||||||
end | ||||||||||||
|
||||||||||||
# wave 3 | ||||||||||||
def score_word(word) | ||||||||||||
Comment on lines
+62
to
+63
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. 👍 |
||||||||||||
# check_input = word.split(//) | ||||||||||||
# print check_input | ||||||||||||
score = 0 | ||||||||||||
word.split(//).each do |letter| | ||||||||||||
case letter.upcase | ||||||||||||
when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" | ||||||||||||
score += 1 | ||||||||||||
when "D", "G" | ||||||||||||
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 >= 7 && word.length <= 10 | ||||||||||||
score += 8 | ||||||||||||
end | ||||||||||||
|
||||||||||||
return score | ||||||||||||
end | ||||||||||||
|
||||||||||||
# wave 4 | ||||||||||||
def highest_score_from(words) | ||||||||||||
Comment on lines
+93
to
+94
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. 👍 Well done! |
||||||||||||
highest_score = 0 | ||||||||||||
highest_score_length = 0 | ||||||||||||
highest_word = nil | ||||||||||||
|
||||||||||||
words.each do |word| | ||||||||||||
score = score_word(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.
Suggested change
|
||||||||||||
|
||||||||||||
if highest_score < score | ||||||||||||
highest_score = score | ||||||||||||
highest_word = word | ||||||||||||
highest_score_length = word.length | ||||||||||||
elsif highest_score == score && highest_score_length != 10 | ||||||||||||
if word.length == 10 | ||||||||||||
highest_score_length = word.length | ||||||||||||
highest_word = word | ||||||||||||
elsif word.length < highest_word.length | ||||||||||||
highest_score_length = word | ||||||||||||
highest_word = word | ||||||||||||
end | ||||||||||||
end | ||||||||||||
end | ||||||||||||
|
||||||||||||
highest_score_hash = { | ||||||||||||
:word => highest_word, | ||||||||||||
:score => highest_score | ||||||||||||
} | ||||||||||||
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.
👍 Straightforward, and effective