diff --git a/.rakeTasks b/.rakeTasks new file mode 100644 index 0000000..f88db1a --- /dev/null +++ b/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/Gemfile.lock b/Gemfile.lock index 878af75..a6092b7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,6 +23,7 @@ GEM PLATFORMS ruby + x64-mingw32 DEPENDENCIES minitest diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..bcc5057 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,102 @@ +# WAVE 1 - The method draw_letters extracts a sample of 10 letters from the letter_pool array +def draw_letters + letter_pool = %w( + 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 + Z +) + return letter_pool.sample(10) + +end + +# WAVE 2 - The method uses_available_letters? checks input against letters_in_hand and returns true if input is in letters_in_hand, false otherwise +def uses_available_letters?(input, letters_in_hand) + + new_letters_in_hand = letters_in_hand.dup + + input.upcase.chars.each do |character| + if new_letters_in_hand.include?(character) + position = new_letters_in_hand.index(character) + new_letters_in_hand.delete_at(position) + else + return false + end + end + return true +end + +# WAVE 3 - The method score_word will tally points for words submitted by user +def score_word(word) + + score = 0 + + word_char_array = word.upcase.chars + + word_char_array.each do |character| + case character + 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_char_array.length >= 7 + score += 8 + end + + return score +end + + +# WAVE 4 - The method highest_score_from returns the winning word and winning score; checks ties +def highest_score_from(words) + + winner = {word: nil, score: 0} + words.each do |word| + + if score_word(word) > winner[:score] + winner[:word] = word + winner[:score] = score_word(word) + elsif score_word(word) == winner[:score] + if ((winner[:word]).length != 10) && (word.length < (winner[:word]).length || word.length == 10) + winner[:word] = word + winner[:score] = score_word(word) + end + end + end + return winner +end \ No newline at end of file