From d03b141b08d3ea3dada806cbfb878bab058d8ca2 Mon Sep 17 00:00:00 2001 From: Genevieve Neely Date: Mon, 14 Sep 2020 15:32:11 -0700 Subject: [PATCH 1/5] finish wave 1 --- lib/adagrams.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..aef2701 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,29 @@ + +def draw_letters() + hand = [] + + letter_dist = { + "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 + } + + letter_pool = [] + + letter_dist.each do |letter, times| + letter_pool << Array.new(times) { letter } + end + + letter_pool = letter_pool.flatten + + until hand.length == 10 do + index = rand(letter_pool.length) + + hand << letter_pool[index] + letter_pool.delete_at(index) + end + return hand +end + +puts "#{draw_letters()}" From 667dcaeb7e4fca96a81c56d011185e896845cbd9 Mon Sep 17 00:00:00 2001 From: Genevieve Neely Date: Mon, 14 Sep 2020 17:40:01 -0700 Subject: [PATCH 2/5] implement score_word method --- lib/adagrams.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index aef2701..bd4cce8 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -26,4 +26,33 @@ def draw_letters() return hand end -puts "#{draw_letters()}" +def uses_available_letters?(input, letters_in_hand) + copy_lih = letters_in_hand.dup + input.each_char do |letter| + if copy_lih.include?(letter) + copy_lih.delete_at(copy_lih.find_index(letter)) + else + return false + end + end + return true +end + +def score_word(word) + score_chart = { + "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 + } + + score = 0 + + word.upcase.each_char do |letter| + score += score_chart[letter] + end + + score += 8 if word.length >= 7 + + return score +end From ea041cb838e05da83d64a8b943898a504c72f548 Mon Sep 17 00:00:00 2001 From: Genevieve Neely Date: Tue, 15 Sep 2020 17:26:57 -0700 Subject: [PATCH 3/5] implement highest_score_from method --- lib/adagrams.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index bd4cce8..b460f5f 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -56,3 +56,25 @@ def score_word(word) return score end + +def highest_score_from(words) + max_score = 0 + highest_word = "" + + words.each do |word| + if score_word(word) > max_score + max_score = score_word(word) + highest_word = word + elsif score_word(word) == max_score && word.length == highest_word.length + next + elsif score_word(word) == max_score && word.length == 10 + max_score = score_word(word) + highest_word = word + elsif score_word(word) == max_score && word.length < highest_word.length && highest_word.length != 10 + max_score = score_word(word) + highest_word = word + end + end + score_hash = { word: highest_word, score: max_score} + return score_hash +end From 6a75381164f64e65ae31e31e740dbb80f09f1e8c Mon Sep 17 00:00:00 2001 From: Genevieve Neely Date: Thu, 17 Sep 2020 15:10:53 -0700 Subject: [PATCH 4/5] add wave 5 & tests --- .gitignore | 1 + lib/adagrams.rb | 6 ++++++ test/adagrams_test.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index 763d4cc..ac2d99a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .env .idea +.test.rb diff --git a/lib/adagrams.rb b/lib/adagrams.rb index b460f5f..5f373be 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,3 +1,4 @@ +require 'csv' def draw_letters() hand = [] @@ -78,3 +79,8 @@ def highest_score_from(words) score_hash = { word: highest_word, score: max_score} return score_hash end + +def is_in_english_dict?(input) + dict = CSV.read('assets/dictionary-english.csv') + dict.include?([input.downcase]) ? true : false +end \ No newline at end of file diff --git a/test/adagrams_test.rb b/test/adagrams_test.rb index 90ec44d..b0c0edf 100644 --- a/test/adagrams_test.rb +++ b/test/adagrams_test.rb @@ -177,5 +177,18 @@ expect(best_word[:word]).must_equal words.first expect(best_word[:score]).must_equal 18 end + + it 'checks an input string against a list of valid English words' do + + word1 = "APPLE" + word2 = "PENCIL" + word3 = "pppppppppp" + word4 = "PROGRAMMING" + + expect(is_in_english_dict?(word1)).must_equal true + expect(is_in_english_dict?(word2)).must_equal true + expect(is_in_english_dict?(word3)).must_equal false + expect(is_in_english_dict?(word4)).must_equal false + end end end From 38e4072172002ab23e33b22d397e8be75d35a83c Mon Sep 17 00:00:00 2001 From: Genevieve Neely Date: Mon, 21 Sep 2020 12:45:53 -0700 Subject: [PATCH 5/5] fixed desc for wave 5 test --- test/adagrams_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/adagrams_test.rb b/test/adagrams_test.rb index b0c0edf..064c6e8 100644 --- a/test/adagrams_test.rb +++ b/test/adagrams_test.rb @@ -177,11 +177,13 @@ expect(best_word[:word]).must_equal words.first expect(best_word[:score]).must_equal 18 end + end + describe 'is_in_english_dict?' do it 'checks an input string against a list of valid English words' do word1 = "APPLE" - word2 = "PENCIL" + word2 = "pencil" word3 = "pppppppppp" word4 = "PROGRAMMING"