From b5074c51d33dd3de0fb49ca8df2d6221996c5ea7 Mon Sep 17 00:00:00 2001 From: Maha-ElMais <51499426+Maha-ElMais@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:38:34 -0700 Subject: [PATCH 01/12] Update Gemfile --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 04a9dcd..d209c11 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gem 'minitest-reporters' gem "pry" gem 'minitest-skip' +#hello From 890f5c9179df4ca0f17653db1533fef76f3e0dfc Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 17 Sep 2020 19:55:45 -0700 Subject: [PATCH 02/12] Update Gemfile --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index d209c11..7f40201 100644 --- a/Gemfile +++ b/Gemfile @@ -7,5 +7,3 @@ gem 'minitest-spec' gem 'minitest-reporters' gem "pry" gem 'minitest-skip' - -#hello From 3b337215ed96d7f2f20fef663b24643e5838c549 Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 17 Sep 2020 20:16:22 -0700 Subject: [PATCH 03/12] Added draw_letters method --- lib/adagrams.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..64f6bca 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,37 @@ +# 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 \ No newline at end of file From 1d7a1cc02eeb9de0e370e3fe409207839539b43b Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 17 Sep 2020 20:20:13 -0700 Subject: [PATCH 04/12] Added uses_available_letters? method --- lib/adagrams.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 64f6bca..d50fec4 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -34,4 +34,19 @@ def draw_letters 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 \ No newline at end of file From 9b5540714a09851cab17fea243e70f721e2bba2f Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 17 Sep 2020 20:22:36 -0700 Subject: [PATCH 05/12] Added score_word method --- lib/adagrams.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index d50fec4..8f3c457 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -49,4 +49,33 @@ def uses_available_letters?(input, letters_in_hand) end return true +end + +# Wave 3 +def score_word(word) + score_chart = { + 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 \ No newline at end of file From ba40f80020ad6d268b3f84cf960e550d120a8b6b Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 17 Sep 2020 20:24:25 -0700 Subject: [PATCH 06/12] Added highest_score_from method --- lib/adagrams.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 8f3c457..3192e9d 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -78,4 +78,34 @@ def score_word(word) 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 + 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 \ No newline at end of file From bba3c2522eaff5ba62439248f9640999de18c84f Mon Sep 17 00:00:00 2001 From: Maha-ElMais Date: Fri, 18 Sep 2020 15:23:05 -0700 Subject: [PATCH 07/12] Wave 5 --- .floo | 3 ++ .flooignore | 6 +++ lib/adagrams.rb | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ wave-1-game.rb | 1 + 4 files changed, 130 insertions(+) create mode 100644 .floo create mode 100644 .flooignore diff --git a/.floo b/.floo new file mode 100644 index 0000000..210ac29 --- /dev/null +++ b/.floo @@ -0,0 +1,3 @@ +{ + "url": "https://floobits.com/ada5l/adagrams" +} \ No newline at end of file diff --git a/.flooignore b/.flooignore new file mode 100644 index 0000000..ed824d3 --- /dev/null +++ b/.flooignore @@ -0,0 +1,6 @@ +extern +node_modules +tmp +vendor +.idea/workspace.xml +.idea/misc.xml diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..33f3fb9 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,120 @@ +# 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 = { + 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 + 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) +end \ No newline at end of file diff --git a/wave-1-game.rb b/wave-1-game.rb index 159f620..c690d75 100644 --- a/wave-1-game.rb +++ b/wave-1-game.rb @@ -16,3 +16,4 @@ def run_game end run_game + From 42a13346eed3ef85e0b3e905bc1f7273132a782e Mon Sep 17 00:00:00 2001 From: beauttie Date: Fri, 18 Sep 2020 15:29:54 -0700 Subject: [PATCH 08/12] Added is_in_english_dict? method --- lib/adagrams.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 3192e9d..33f3fb9 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -108,4 +108,13 @@ def highest_score_from(words) } 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) end \ No newline at end of file From 57d27c44f6fb7d4b874ff2b0e6c02d37f6aa0209 Mon Sep 17 00:00:00 2001 From: beauttie Date: Fri, 18 Sep 2020 16:24:18 -0700 Subject: [PATCH 09/12] Removed white spaces and relative path in Wave 5 --- lib/adagrams.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index eaa3d57..be331e1 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -108,15 +108,13 @@ def highest_score_from(words) } 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"] } + dictionary = CSV.read('assets/dictionary-english.csv', headers: true).map { |word| word["Word"] } return dictionary.include?(input.downcase) - -end \ No newline at end of file +end From 50857177b21e2ef18d05fe43210f57d348a19e4a Mon Sep 17 00:00:00 2001 From: beauttie Date: Fri, 18 Sep 2020 16:26:34 -0700 Subject: [PATCH 10/12] Delete .floo --- .floo | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .floo diff --git a/.floo b/.floo deleted file mode 100644 index 210ac29..0000000 --- a/.floo +++ /dev/null @@ -1,3 +0,0 @@ -{ - "url": "https://floobits.com/ada5l/adagrams" -} \ No newline at end of file From 6180ede9a8f7773a0f57135460fb5a52d622fdb8 Mon Sep 17 00:00:00 2001 From: beauttie Date: Fri, 18 Sep 2020 16:27:00 -0700 Subject: [PATCH 11/12] Delete .flooignore --- .flooignore | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .flooignore diff --git a/.flooignore b/.flooignore deleted file mode 100644 index ed824d3..0000000 --- a/.flooignore +++ /dev/null @@ -1,6 +0,0 @@ -extern -node_modules -tmp -vendor -.idea/workspace.xml -.idea/misc.xml From 5d891fd88d5b8611da66a62b0793ba1185a41a26 Mon Sep 17 00:00:00 2001 From: Maha-ElMais Date: Fri, 18 Sep 2020 19:51:18 -0700 Subject: [PATCH 12/12] dictionary method --- lib/adagrams.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index eaa3d57..eeb0717 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -118,5 +118,5 @@ def is_in_english_dict?(input) dictionary = CSV.read('../assets/dictionary-english.csv', headers: true).map { |word| word["Word"] } return dictionary.include?(input.downcase) - + end \ No newline at end of file