-
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
ports- cloudy and mina #2
base: master
Are you sure you want to change the base?
Changes from all commits
9db2d39
a177384
6b204c3
202fb10
c800202
7e989e4
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,55 @@ | ||
# Wave 1 [Question 1 - Creating Data Structure] | ||
|
||
# POOL_OF_LETTERS = [ | ||
# {A: 9}, {N: 6}, | ||
# {B: 2}, {O: 8}, | ||
# {C: 2}, {P: 2}, | ||
# {D: 4}, {Q: 1}, | ||
# {E: 12}, {R: 6}, | ||
# {F: 2}, {S: 4}, | ||
# {G: 3}, {T: 6}, | ||
# {H: 2}, {U: 4}, | ||
# {I: 9}, {V: 2}, | ||
# {J: 1}, {W: 2}, | ||
# {K: 1}, {X: 1}, | ||
# {L: 4}, {Y: 2}, | ||
# {M: 2}, {Z: 1} | ||
# ] | ||
|
||
$POOL_OF_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" | ||
] | ||
|
||
def draw_letters | ||
my_letters = [] | ||
10.times do | ||
random_letter = $POOL_OF_LETTERS.shuffle | ||
my_letters.push(random_letter[-1]) | ||
random_letter.pop | ||
end | ||
return my_letters | ||
end | ||
|
||
def uses_available_letters?(input, letters_in_hand) | ||
word = input.split(//) | ||
|
||
if word.length <= 10 | ||
word.each do |each_letter_in_word| | ||
if !letters_in_hand.include?(each_letter_in_word) | ||
return false | ||
end | ||
letters_in_hand.delete(each_letter_in_word) | ||
end | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
drawn_letters = draw_letters | ||
print "Your 10 letters are #{ drawn_letters }." | ||
|
||
puts "Please make the best work with the letters you were dealt." | ||
new_word = gets.chomp.to_s.upcase | ||
|
||
uses_available_letters?(new_word, drawn_letters) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Wave 1 [Question 1 - Creating Data Structure] | ||
|
||
def draw_letters | ||
pool_of_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" | ||
] | ||
my_letters = [] | ||
random_letter = pool_of_letters.shuffle | ||
10.times do | ||
my_letters.push(random_letter[-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. Just to make it clear what's going on: You have the There are also interesting things that |
||
random_letter.pop | ||
end | ||
return my_letters | ||
end | ||
|
||
def uses_available_letters?(input, letters_in_hand) | ||
word = input.upcase.split(//) | ||
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 just remembered that I was supposed to get in touch with Cloudy so that her VS Code indented with 2 spaces instead of 4 :) |
||
if word.length <= 10 | ||
word.each do |each_letter_in_word| | ||
if !letters_in_hand.include?(each_letter_in_word) | ||
return false | ||
end | ||
letters_in_hand.delete_at(letters_in_hand.index(each_letter_in_word)) | ||
end | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
|
||
def score_word(word) | ||
letter_points = { | ||
"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 | ||
} | ||
word_to_score = word.upcase.split(//) | ||
score = word_to_score.map do |each_letter| | ||
letter_points[each_letter] | ||
end | ||
my_score = score.inject(0) do |total_score, letter_value| | ||
total_score + letter_value | ||
end | ||
if word_to_score.length > 6 | ||
my_score += 8 | ||
end | ||
|
||
return my_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. Nice method implementation, and nice use of Enumerable methods! |
||
end | ||
|
||
# Wave 4 - Here we goooo. | ||
|
||
def highest_score_from(words) | ||
winning_hash = { | ||
word: "", | ||
score: 0 | ||
} | ||
words.each do |word| | ||
if score_word(word) > winning_hash[:score] | ||
winning_hash[:word] = word | ||
winning_hash[:score] = score_word(word) | ||
elsif score_word(word) == winning_hash[:score] | ||
if word.length == 10 && winning_hash[:word].length != 10 | ||
winning_hash[:word] = word | ||
elsif word.length < winning_hash[:word].length && winning_hash[:word].length != 10 | ||
winning_hash[:word] = word | ||
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. This complex logic is really readable-- good work on this wave! |
||
end | ||
return winning_hash | ||
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, feel free to delete any unused files before submitting!