From 68c6df6599801ebc0c9c35b5eaa82247fc50431d Mon Sep 17 00:00:00 2001 From: Dominique Taylor Date: Mon, 12 Aug 2019 15:51:46 -0700 Subject: [PATCH 1/5] wave 1 adagrams.rb --- lib/adagrams.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..053800a 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,23 @@ +def draw_letters + raw_tiles = [{letter: "A", weight: 9}, {letter: "B", weight: 2}, {letter: "C", weight: 2}, + {letter: "D", weight: 4}, {letter: "E", weight: 12}, {letter: "F", weight: 2}, {letter: "G", weight: 3}, + {letter: "H", weight: 2}, {letter: "I", weight: 9}, {letter: "J", weight: 1}, {letter: "K", weight: 1}, + {letter: "L", weight: 4}, {letter: "M", weight: 2}, {letter: "N", weight: 6}, {letter: "O", weight: 8}, + {letter: "P", weight: 2}, {letter: "Q", weight: 1}, {letter: "R", weight: 6}, {letter: "S", weight: 4}, + {letter: "T", weight: 6}, {letter: "U", weight: 4}, {letter: "V", weight: 2}, {letter: "W", weight: 2}, + {letter: "X", weight: 1}, {letter: "Y", weight: 2}, {letter: "Z", weight: 1}] + tile_set = [] + + raw_tiles.each do |a| + a[:weight].times do + tile_set.push(a[:letter]) + end + end + + hand_array = [] + hand = tile_set.sample(10) + hand_array = hand.join(" ") + return hand_array + end + + print draw_letters \ No newline at end of file From 9be744a1719280584ff74de21a609eef7cf666db Mon Sep 17 00:00:00 2001 From: Dominique Taylor Date: Wed, 14 Aug 2019 14:17:19 -0700 Subject: [PATCH 2/5] Wave 1 Test Pass adagrams.rb --- lib/adagrams.rb | 120 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 98 insertions(+), 22 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 053800a..72423b6 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,23 +1,99 @@ + +# wave_1 def draw_letters - raw_tiles = [{letter: "A", weight: 9}, {letter: "B", weight: 2}, {letter: "C", weight: 2}, - {letter: "D", weight: 4}, {letter: "E", weight: 12}, {letter: "F", weight: 2}, {letter: "G", weight: 3}, - {letter: "H", weight: 2}, {letter: "I", weight: 9}, {letter: "J", weight: 1}, {letter: "K", weight: 1}, - {letter: "L", weight: 4}, {letter: "M", weight: 2}, {letter: "N", weight: 6}, {letter: "O", weight: 8}, - {letter: "P", weight: 2}, {letter: "Q", weight: 1}, {letter: "R", weight: 6}, {letter: "S", weight: 4}, - {letter: "T", weight: 6}, {letter: "U", weight: 4}, {letter: "V", weight: 2}, {letter: "W", weight: 2}, - {letter: "X", weight: 1}, {letter: "Y", weight: 2}, {letter: "Z", weight: 1}] - tile_set = [] - - raw_tiles.each do |a| - a[:weight].times do - tile_set.push(a[:letter]) - end - end - - hand_array = [] - hand = tile_set.sample(10) - hand_array = hand.join(" ") - return hand_array - end - - print draw_letters \ No newline at end of file + raw_tiles = [ + {letter: "A", weight: 9, score: 1}, + {letter: "B", weight: 2, score: 3}, + {letter: "C", weight: 2, score: 3}, + {letter: "D", weight: 4, score: 2}, + {letter: "E", weight: 12, score: 1}, + {letter: "F", weight: 2, score: 4}, + {letter: "G", weight: 3, score: 2}, + {letter: "H", weight: 2, score: 4}, + {letter: "I", weight: 9, score: 1}, + {letter: "J", weight: 1, score: 8}, + {letter: "K", weight: 1, score: 5}, + {letter: "L", weight: 4, score: 1}, + {letter: "M", weight: 2, score: 3}, + {letter: "N", weight: 6, score: 1}, + {letter: "O", weight: 8, score: 1}, + {letter: "P", weight: 2, score: 3}, + {letter: "Q", weight: 1, score: 10}, + {letter: "R", weight: 6, score: 1}, + {letter: "S", weight: 4, score: 1}, + {letter: "T", weight: 6, score: 1}, + {letter: "U", weight: 4, score: 1}, + {letter: "V", weight: 2, score: 4}, + {letter: "W", weight: 2, score: 4}, + {letter: "X", weight: 1, score: 8}, + {letter: "Y", weight: 2, score: 4}, + {letter: "Z", weight: 1, score: 10}] + tile_set = [] + + # extracts letter and score keys and puts them in array called raw_tiles + raw_tiles.each do |a| + a[:weight].times do + tile_set.push(a[:letter]) + end + end + + # extracts 10 random letters and assigns them to the array named hand + hand = tile_set.sample(10) + return hand + end + #Official hand + + hand = draw_letters + + +# #Wave 2 +# #User submits word to be tested +# puts "\n\nPlease provide a word:" +# word = gets.chomp.upcase + +# #Word is changed to array so we can see if the word is an anagram of the hand +# submit = word.chars +# print submit + +# def uses_available_letters?(input, letters_in_hand) +# boolean_value = true +# input.each do |letter| +# if input.count(letter) > letters_in_hand.count(letter) +# boolean_value = false +# end +# end +# boolean_value +# end + +# puts uses_available_letters?(submit, hand) + +# # Wave 3 +# # Return the score of the given word + +# def score_word(word) +# total_sum = 0 +# score_hash = {1=> ["A", "E", "I", "0", "U", "L", "N", "R", "S", "T"], 2=> ["D", "G"], +# 3=> ["B", "C", "M", "P"], 4=> ["F", "H", "V", "W", "Y"], 5=> "K", 8=> ["J", "X"], +# 10=> ["Q", "Z"]} +# word.each do |letter| +# sum = score_hash.key(letter) +# # need a way to acccess the letters in the values +# total_sum += sum +# end +# end + +# puts score_word(submit) + + + + + + + + + + + + + + From 746e1c5ce37f43fc8f34849384802ba4b60644e9 Mon Sep 17 00:00:00 2001 From: Dominique Taylor Date: Wed, 14 Aug 2019 14:38:47 -0700 Subject: [PATCH 3/5] Wave 2 test pass adagrams.rb --- lib/adagrams.rb | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 72423b6..2d43039 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -28,6 +28,7 @@ def draw_letters {letter: "X", weight: 1, score: 8}, {letter: "Y", weight: 2, score: 4}, {letter: "Z", weight: 1, score: 10}] + tile_set = [] # extracts letter and score keys and puts them in array called raw_tiles @@ -41,31 +42,25 @@ def draw_letters hand = tile_set.sample(10) return hand end - #Official hand - - hand = draw_letters + #Official hand -# #Wave 2 -# #User submits word to be tested -# puts "\n\nPlease provide a word:" -# word = gets.chomp.upcase + letters_in_hand = draw_letters -# #Word is changed to array so we can see if the word is an anagram of the hand -# submit = word.chars -# print submit + #Wave 2 -# def uses_available_letters?(input, letters_in_hand) -# boolean_value = true -# input.each do |letter| -# if input.count(letter) > letters_in_hand.count(letter) -# boolean_value = false -# end -# end -# boolean_value -# end + #Word is changed to array so we can see if the word is an anagram of the hand -# puts uses_available_letters?(submit, hand) + def uses_available_letters?(input, letters_in_hand) + input = input.upcase.chars + boolean_value = true + input.each do |letter| + if input.count(letter) > letters_in_hand.count(letter) + boolean_value = false + end + end + boolean_value + end # # Wave 3 # # Return the score of the given word From fb2885ba1ef28e5cadee1c63d53d8fd8032df374 Mon Sep 17 00:00:00 2001 From: Dominique Taylor Date: Wed, 14 Aug 2019 16:54:11 -0700 Subject: [PATCH 4/5] Wave 3 test pass adagrams.rb --- lib/adagrams.rb | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 2d43039..543ff4c 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -62,22 +62,33 @@ def uses_available_letters?(input, letters_in_hand) boolean_value end -# # Wave 3 -# # Return the score of the given word - -# def score_word(word) -# total_sum = 0 -# score_hash = {1=> ["A", "E", "I", "0", "U", "L", "N", "R", "S", "T"], 2=> ["D", "G"], -# 3=> ["B", "C", "M", "P"], 4=> ["F", "H", "V", "W", "Y"], 5=> "K", 8=> ["J", "X"], -# 10=> ["Q", "Z"]} -# word.each do |letter| -# sum = score_hash.key(letter) -# # need a way to acccess the letters in the values -# total_sum += sum -# end -# end - -# puts score_word(submit) +# Wave 3 +# Return the score of the given word + +def score_word(word) + word = word.upcase.chars + sum = 0 + total_sum = 0 + + score_hash = {1=> ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], 2=> ["D", "G"], + 3=> ["B", "C", "M", "P"], 4=> ["F", "H", "V", "W", "Y"], 5=> ["K"], 8=> ["J", "X"], + 10=> ["Q", "Z"]} + + total_sum = 8 if word.length >= 7 + word.each do |letter| + score_hash.each do |key, value| + value.each do |check| + if check == letter + sum = key.to_i + print sum + total_sum += sum + end + end + end + end + return total_sum +end + From 78cd2955a348d0efe3b4c0a65d0124e8434adbce Mon Sep 17 00:00:00 2001 From: Dominique Taylor Date: Thu, 15 Aug 2019 15:14:08 -0700 Subject: [PATCH 5/5] Wave 4 test pass adagrams.rb --- lib/adagrams.rb | 160 ++++++++++++++++++++++++++++++------------------ 1 file changed, 100 insertions(+), 60 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 543ff4c..1f8d019 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,70 +1,65 @@ - -# wave_1 +# Wave 1 def draw_letters raw_tiles = [ - {letter: "A", weight: 9, score: 1}, - {letter: "B", weight: 2, score: 3}, - {letter: "C", weight: 2, score: 3}, - {letter: "D", weight: 4, score: 2}, - {letter: "E", weight: 12, score: 1}, - {letter: "F", weight: 2, score: 4}, - {letter: "G", weight: 3, score: 2}, - {letter: "H", weight: 2, score: 4}, - {letter: "I", weight: 9, score: 1}, - {letter: "J", weight: 1, score: 8}, - {letter: "K", weight: 1, score: 5}, - {letter: "L", weight: 4, score: 1}, - {letter: "M", weight: 2, score: 3}, - {letter: "N", weight: 6, score: 1}, - {letter: "O", weight: 8, score: 1}, - {letter: "P", weight: 2, score: 3}, - {letter: "Q", weight: 1, score: 10}, - {letter: "R", weight: 6, score: 1}, - {letter: "S", weight: 4, score: 1}, - {letter: "T", weight: 6, score: 1}, - {letter: "U", weight: 4, score: 1}, - {letter: "V", weight: 2, score: 4}, - {letter: "W", weight: 2, score: 4}, - {letter: "X", weight: 1, score: 8}, - {letter: "Y", weight: 2, score: 4}, - {letter: "Z", weight: 1, score: 10}] - - tile_set = [] - - # extracts letter and score keys and puts them in array called raw_tiles - raw_tiles.each do |a| - a[:weight].times do - tile_set.push(a[:letter]) - end + {letter: "A", weight: 9, score: 1}, + {letter: "B", weight: 2, score: 3}, + {letter: "C", weight: 2, score: 3}, + {letter: "D", weight: 4, score: 2}, + {letter: "E", weight: 12, score: 1}, + {letter: "F", weight: 2, score: 4}, + {letter: "G", weight: 3, score: 2}, + {letter: "H", weight: 2, score: 4}, + {letter: "I", weight: 9, score: 1}, + {letter: "J", weight: 1, score: 8}, + {letter: "K", weight: 1, score: 5}, + {letter: "L", weight: 4, score: 1}, + {letter: "M", weight: 2, score: 3}, + {letter: "N", weight: 6, score: 1}, + {letter: "O", weight: 8, score: 1}, + {letter: "P", weight: 2, score: 3}, + {letter: "Q", weight: 1, score: 10}, + {letter: "R", weight: 6, score: 1}, + {letter: "S", weight: 4, score: 1}, + {letter: "T", weight: 6, score: 1}, + {letter: "U", weight: 4, score: 1}, + {letter: "V", weight: 2, score: 4}, + {letter: "W", weight: 2, score: 4}, + {letter: "X", weight: 1, score: 8}, + {letter: "Y", weight: 2, score: 4}, + {letter: "Z", weight: 1, score: 10}] + + tile_set = [] + + # extracts letter and score keys and puts them in array called raw_tiles + raw_tiles.each do |a| + a[:weight].times do + tile_set.push(a[:letter]) end - - # extracts 10 random letters and assigns them to the array named hand - hand = tile_set.sample(10) - return hand end - #Official hand - - letters_in_hand = draw_letters - - #Wave 2 - - #Word is changed to array so we can see if the word is an anagram of the hand - - def uses_available_letters?(input, letters_in_hand) - input = input.upcase.chars - boolean_value = true - input.each do |letter| - if input.count(letter) > letters_in_hand.count(letter) - boolean_value = false - end - end - boolean_value - end + # extracts 10 random letters and assigns them to the array named hand + hand = tile_set.sample(10) + return hand +end + +#Official hand +letters_in_hand = draw_letters + +#Wave 2 +#Word is changed to array so we can see if the word is an anagram of the hand +def uses_available_letters?(input, letters_in_hand) + input = input.upcase.chars + boolean_value = true + input.each do |letter| + if input.count(letter) > letters_in_hand.count(letter) + boolean_value = false + end + end + boolean_value +end # Wave 3 # Return the score of the given word - def score_word(word) word = word.upcase.chars sum = 0 @@ -80,7 +75,6 @@ def score_word(word) value.each do |check| if check == letter sum = key.to_i - print sum total_sum += sum end end @@ -89,6 +83,52 @@ def score_word(word) return total_sum end +# Wave 4 +# Return word and score of word with highest score +def highest_score_from(words) + high_score_hash = {word: "", score: 0} + high_score = 0 + high_score_length = 0 + words.each do |word| + score = score_word(word) + if score > high_score_hash[:score] + high_score_hash[:score] = score_word(word) + high_score_hash[:word] = word + elsif score == high_score_hash[:score] + winner_word = tiebreaker(high_score_hash[:word], word) + high_score_hash[:score] = score + high_score_hash[:word] = winner_word + end + end + return high_score_hash +end + +def tiebreaker(word1, word2) + if word1.length == 10 + return word1 + elsif word2.length == 10 + return word2 + elsif word1.length < word2.length + return word1 + elsif word2.length < word1.length + return word2 + end + return word1 +end + + + + + + + + + + + + + +