From 9c8676c39c7a92070092ea3fae3bff764fb208f1 Mon Sep 17 00:00:00 2001 From: MyriamWD Date: Thu, 21 Feb 2019 14:54:56 -0800 Subject: [PATCH 1/3] First three waves --- lib/adagrams.rb | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..659e89c 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,126 @@ +def draw_letters + alphabet = [ + "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", "Y", + "Z", + ] + + hand = alphabet.sample(10) + + return hand +end + +letters_in_hand = draw_letters + +# Returns either true or false +# Returns true if every letter in the input word is available (in the right quantities) +# in the letters_in_hand +# Returns false if not; if there is a letter in input that is not present in the letters_in_hand or +# has too much of compared to the letters_in_hand + +puts "#{letters_in_hand}" +puts "Please enter an adagram" +input = gets.chomp.upcase! + +def uses_available_letters?(input, letters_in_hand) + input_array = input.split("") + return (input_array - letters_in_hand).empty? +end + +#puts uses_available_letters?(input, letters_in_hand) + +# #Has one parameter: word, which is a string of characters +# Returns an integer representing the number of points +# Each letter within word has a point value. The number of points of each letter is +# summed up to represent the total score of word +# Each letter's point value is described in the table below +# If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points +def score_word(word) + points = 0 + word_array = word.split("") + puts word_array + word_array.each do |letter| + point_1 = ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"] + point_1.each do |letter_p| + if letter_p == letter + points += 1 + end + end + point_2 = ["D", "G"] + point_2.each do |letter_p| + if letter_p == letter + points += 2 + end + end + point_3 = ["B", "C", "M", "P"] + point_3.each do |letter_p| + if letter_p == letter + points += 3 + end + end + point_4 = ["F", "H", "V", "W", "Y"] + point_4.each do |letter_p| + if letter_p == letter + points += 4 + end + end + point_5 = ["K"] + point_5.each do |letter_p| + if letter_p == letter + points += 5 + end + end + point_8 = ["J", "X"] + point_8.each do |letter_p| + if letter_p == letter + points += 8 + end + end + point_10 = ["Q", "Z"] + point_10.each do |letter_p| + if letter_p == letter + points += 10 + end + end + end + if word_array.length >= 7 || word_array.length <= 10 + points += 8 + end + return points +end + +puts score_word(input) + +# need to figure out how to store the point values for each letter +# how to know what letters the input contains so we can assign point values +# if/else case/when / count + +# A, E, I, O, U, L, N, R, S, T 1 +# D, G 2 +# B, C, M, P 3 +# F, H, V, W, Y 4 +# K 5 +# J, X 8 +# Q, Z 10 From b62aa4fa9b865a8bdd14370ca20a9f6c74b3ff93 Mon Sep 17 00:00:00 2001 From: MyriamWD Date: Thu, 21 Feb 2019 17:38:52 -0800 Subject: [PATCH 2/3] Updated wave 4 incomplete --- lib/adagrams.rb | 92 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 659e89c..d693661 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -34,33 +34,15 @@ def draw_letters letters_in_hand = draw_letters -# Returns either true or false -# Returns true if every letter in the input word is available (in the right quantities) -# in the letters_in_hand -# Returns false if not; if there is a letter in input that is not present in the letters_in_hand or -# has too much of compared to the letters_in_hand - -puts "#{letters_in_hand}" -puts "Please enter an adagram" -input = gets.chomp.upcase! - def uses_available_letters?(input, letters_in_hand) input_array = input.split("") return (input_array - letters_in_hand).empty? end -#puts uses_available_letters?(input, letters_in_hand) - -# #Has one parameter: word, which is a string of characters -# Returns an integer representing the number of points -# Each letter within word has a point value. The number of points of each letter is -# summed up to represent the total score of word -# Each letter's point value is described in the table below -# If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points def score_word(word) points = 0 + scores = [] word_array = word.split("") - puts word_array word_array.each do |letter| point_1 = ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"] point_1.each do |letter_p| @@ -105,22 +87,70 @@ def score_word(word) end end end - if word_array.length >= 7 || word_array.length <= 10 + if word_array.length >= 7 points += 8 end + scores << points + return points end -puts score_word(input) +def highest_score_from(words) + scores = [] + words.each_with_index do |word, index| + scores << [score_word(word), word] + end + + maximum = scores.max + max = maximum[0] + puts "#{maximum}" + + tie = scores.flat_map { |i| i } + variable = tie.count(max) + puts variable + + high_score = { + word: maximum[0], + score: maximum[1], + } + puts high_score + return high_score +end + +# count = words.count(maximum[0]) +#puts count +# HERE +# scores flat map then count to see if there's a tie for max value + +# scores.each do |array| +# if array[0].include?(maximum[0]) +# puts "it's there #{array}" +# end +# end + +# puts count + +# puts "#{scores}" + +# -------- +# puts "#{words}" +# word_score = score_word(word) +# puts "#{top_score}" +# high_score = words.max_by {|word| word_score } +# variable = words[0] +# word_score = score_word(variable) +# puts word_score -# need to figure out how to store the point values for each letter -# how to know what letters the input contains so we can assign point values -# if/else case/when / count +# highest_score_from(words) +# puts score_word(input) -# A, E, I, O, U, L, N, R, S, T 1 -# D, G 2 -# B, C, M, P 3 -# F, H, V, W, Y 4 -# K 5 -# J, X 8 -# Q, Z 10 +# In the case of tie in scores, use these tie-breaking +# rules: +# prefer the word with the fewest letters... +# ...unless one word has 10 letters. If the top score +# is tied between multiple words and one is 10 letters +#long, choose the one with 10 letters over the one with +#fewer tiles +# If the there are multiple words that are the same +#score and the same length, pick the first one in the +#supplied list From d5c6c3e38063c24d4386da180e69cf7ba91b3af0 Mon Sep 17 00:00:00 2001 From: MyriamWD Date: Fri, 22 Feb 2019 17:04:46 -0800 Subject: [PATCH 3/3] Wave 4 --- lib/adagrams.rb | 50 ++----------------------------------------------- 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index d693661..e9b5dd4 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -102,55 +102,9 @@ def highest_score_from(words) end maximum = scores.max - max = maximum[0] - puts "#{maximum}" - - tie = scores.flat_map { |i| i } - variable = tie.count(max) - puts variable - high_score = { - word: maximum[0], - score: maximum[1], + word: maximum[1], + score: maximum[0], } - puts high_score return high_score end - -# count = words.count(maximum[0]) -#puts count -# HERE -# scores flat map then count to see if there's a tie for max value - -# scores.each do |array| -# if array[0].include?(maximum[0]) -# puts "it's there #{array}" -# end -# end - -# puts count - -# puts "#{scores}" - -# -------- -# puts "#{words}" -# word_score = score_word(word) -# puts "#{top_score}" -# high_score = words.max_by {|word| word_score } -# variable = words[0] -# word_score = score_word(variable) -# puts word_score - -# highest_score_from(words) -# puts score_word(input) - -# In the case of tie in scores, use these tie-breaking -# rules: -# prefer the word with the fewest letters... -# ...unless one word has 10 letters. If the top score -# is tied between multiple words and one is 10 letters -#long, choose the one with 10 letters over the one with -#fewer tiles -# If the there are multiple words that are the same -#score and the same length, pick the first one in the -#supplied list