From 9db2d394f7fd894025b6adf43de89e1d9f9e8109 Mon Sep 17 00:00:00 2001 From: Cloudy Lopez Date: Wed, 20 Feb 2019 15:24:09 -0800 Subject: [PATCH 1/6] wave one complete --- adagram.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 adagram.rb diff --git a/adagram.rb b/adagram.rb new file mode 100644 index 0000000..0543705 --- /dev/null +++ b/adagram.rb @@ -0,0 +1,33 @@ +# Wave 1 [Question 1 - Creating Data Structure] + +# POOL_OF_LETTERS = [ +# {A: 9}, {N: 6}, +# {B: 2}, {O: 8}, +# {C: 2}, {P: 2}, +# {D: 4}, {Q: 1}, +# {E: 12}, {R: 6}, +# {F: 2}, {S: 4}, +# {G: 3}, {T: 6}, +# {H: 2}, {U: 4}, +# {I: 9}, {V: 2}, +# {J: 1}, {W: 2}, +# {K: 1}, {X: 1}, +# {L: 4}, {Y: 2}, +# {M: 2}, {Z: 1} +# ] + +$POOL_OF_LETTERS = [ + "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" +] + +def draw_letters + my_letters = [] + 10.times do + random_letter = $POOL_OF_LETTERS.shuffle + my_letters.push(random_letter[-1]) + random_letter.pop + end + return my_letters +end + +print "Your 10 letters are #{ draw_letters }." From a177384e158f7b7e66354a01e602463b00d1fc78 Mon Sep 17 00:00:00 2001 From: Cloudy Lopez Date: Wed, 20 Feb 2019 16:34:56 -0800 Subject: [PATCH 2/6] Wave 2 complete --- adagram.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/adagram.rb b/adagram.rb index 0543705..750f2f2 100644 --- a/adagram.rb +++ b/adagram.rb @@ -30,4 +30,26 @@ def draw_letters return my_letters end -print "Your 10 letters are #{ draw_letters }." +def uses_available_letters?(input, letters_in_hand) + word = input.split(//) + + if word.length <= 10 + word.each do |each_letter_in_word| + if !letters_in_hand.include?(each_letter_in_word) + return false + end + letters_in_hand.delete(each_letter_in_word) + end + return true + else + return false + end +end + +drawn_letters = draw_letters +print "Your 10 letters are #{ drawn_letters }." + +puts "Please make the best work with the letters you were dealt." + new_word = gets.chomp.to_s.upcase + +uses_available_letters?(new_word, drawn_letters) \ No newline at end of file From 6b204c3d557753e11aadeab8ff517967bef97b79 Mon Sep 17 00:00:00 2001 From: Cloudy Lopez Date: Thu, 21 Feb 2019 15:59:03 -0800 Subject: [PATCH 3/6] wave 3 done --- lib/adagrams.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..c705bee 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,55 @@ +# Wave 1 [Question 1 - Creating Data Structure] + +def draw_letters + pool_of_letters = [ + "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" +] + my_letters = [] + random_letter = pool_of_letters.shuffle + 10.times do + my_letters.push(random_letter[-1]) + random_letter.pop + end + return my_letters +end + +def uses_available_letters?(input, letters_in_hand) + word = input.upcase.split(//) + if word.length <= 10 + word.each do |each_letter_in_word| + if !letters_in_hand.include?(each_letter_in_word) + return false + end + letters_in_hand.delete_at(letters_in_hand.index(each_letter_in_word)) + end + return true + else + return false + end +end + +def score_word(word) + letter_points = { + "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 + } + word_to_score = word.split(//) + score = word_to_score.map do |each_letter| + letter_points[each_letter] + end + my_score = score.inject do |total_score, letter_value| + total_score + letter_value + end + if word_to_score.length > 6 + my_score += 8 + end + return my_score +end +# drawn_letters = draw_letters +# puts "Your 10 letters are #{ drawn_letters }." + +# puts "Please make the best work with the letters you were dealt." +# new_word = gets.chomp.to_s.upcase + +# uses_available_letters?(new_word, drawn_letters) + +# score_word(new_word) \ No newline at end of file From 202fb106d57d6ef2f544a706d60eabc49101da22 Mon Sep 17 00:00:00 2001 From: Cloudy Lopez Date: Thu, 21 Feb 2019 16:02:34 -0800 Subject: [PATCH 4/6] wave 3 complete --- lib/adagrams.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index c705bee..571c387 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -43,13 +43,4 @@ def score_word(word) my_score += 8 end return my_score -end -# drawn_letters = draw_letters -# puts "Your 10 letters are #{ drawn_letters }." - -# puts "Please make the best work with the letters you were dealt." -# new_word = gets.chomp.to_s.upcase - -# uses_available_letters?(new_word, drawn_letters) - -# score_word(new_word) \ No newline at end of file +end \ No newline at end of file From c8002020244f17108598bb6e7eab00188dcdf788 Mon Sep 17 00:00:00 2001 From: Cloudy Lopez Date: Thu, 21 Feb 2019 16:20:43 -0800 Subject: [PATCH 5/6] wave 3 completed- seriously this time --- lib/adagrams.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 571c387..5642c02 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -28,19 +28,21 @@ def uses_available_letters?(input, letters_in_hand) end end + def score_word(word) letter_points = { "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 } - word_to_score = word.split(//) + word_to_score = word.upcase.split(//) score = word_to_score.map do |each_letter| letter_points[each_letter] end - my_score = score.inject do |total_score, letter_value| + my_score = score.inject(0) do |total_score, letter_value| total_score + letter_value end if word_to_score.length > 6 my_score += 8 end + return my_score end \ No newline at end of file From 7e989e4d54d1579bb0a09db1ff524d6479a22247 Mon Sep 17 00:00:00 2001 From: Cloudy Lopez Date: Thu, 21 Feb 2019 17:09:58 -0800 Subject: [PATCH 6/6] wave 4 done- yay --- lib/adagrams.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 5642c02..aa858fa 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -45,4 +45,26 @@ def score_word(word) end return my_score +end + +# Wave 4 - Here we goooo. + +def highest_score_from(words) + winning_hash = { + word: "", + score: 0 + } + words.each do |word| + if score_word(word) > winning_hash[:score] + winning_hash[:word] = word + winning_hash[:score] = score_word(word) + elsif score_word(word) == winning_hash[:score] + if word.length == 10 && winning_hash[:word].length != 10 + winning_hash[:word] = word + elsif word.length < winning_hash[:word].length && winning_hash[:word].length != 10 + winning_hash[:word] = word + end + end + end + return winning_hash end \ No newline at end of file