Skip to content
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

Beauttie and Maha #25

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ gem 'minitest-spec'
gem 'minitest-reporters'
gem "pry"
gem 'minitest-skip'

121 changes: 121 additions & 0 deletions lib/adagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Wave 1
LETTER_DISTRIB = {
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
}

def draw_letters
letter_pool = LETTER_DISTRIB.flat_map { |letter_symbol, freq| [letter_symbol.to_s] * freq }

user_hand = letter_pool.sample(10)

return user_hand
end

# Wave 2
def uses_available_letters?(input, letters_in_hand)
dup_hand = letters_in_hand.dup

input.split("").each do |letter|
if ! dup_hand.include?(letter)
return false
end

dup_hand.delete_at(dup_hand.index(letter))
end

return true
end

# Wave 3
def score_word(word)
score_chart = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of a hash to store this data

1 => %w[A E I O U L N R S T],
2 => %w[D G],
3 => %w[B C M P],
4 => %w[F H V W Y],
5 => %w[K],
8 => %w[J X],
10 => %w[Q Z]
}

score = 0

word.upcase.split("").each do |char|
score_chart.each do |point_value, letters|
if letters.include?(char)
score += point_value
end
end
end

if word.length > 6 && word.length <= 10
score += 8
end

return score
end

# Wave 4
def highest_score_from(words)
scores = words.map { |word| score_word(word) }

max_score = scores.max

if scores.count(max_score) == 1
return {
word: words[scores.index(max_score)],
score: max_score
}
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work working through this tiebreaking logic with the help of some enumerable methods. Consider breaking out this logic into its own method.

highest_scoring_words = words.select { |word| score_word(word) == max_score }

tied_words_length = highest_scoring_words.map { |word| word.length }

if tied_words_length.include?(10)
return {
word: highest_scoring_words[tied_words_length.index(10)],
score: max_score
}
else
return {
word: highest_scoring_words[tied_words_length.index(tied_words_length.min)],
score: max_score
}
end
end
end

# Wave 5
require "csv"

def is_in_english_dict?(input)
dictionary = CSV.read('assets/dictionary-english.csv', headers: true).map { |word| word["Word"] }

return dictionary.include?(input.downcase)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work using .include? to directly return a boolean value.


end
1 change: 1 addition & 0 deletions wave-1-game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ def run_game
end

run_game