Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Untitled Diagram.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<mxfile host="app.diagrams.net" modified="2020-12-18T08:14:57.125Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15" etag="cCoXQTFkrQucJ_5DPNGD" version="14.0.5" type="github">
<diagram id="_95Hr5ytqPnYlgKhDQPe" name="Page-1">
<mxGraphModel dx="874" dy="1604" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="Pv-lDhROw9vmJ1KCem3l-1" value="" style="shape=image;imageAspect=0;aspect=fixed;verticalLabelPosition=bottom;verticalAlign=top;image=https://s3-us-west-2.amazonaws.com/forge-production.galvanize.com/content/c29d2d8a9a36c1542a5f6c8ee3399291.png;" vertex="1" parent="1">
<mxGeometry x="20" y="-151.12" width="787.77" height="671.12" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-2" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="190" y="-100" width="150" height="150" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-3" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="190" y="60" width="150" height="160" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-4" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="360" y="-100" width="170" height="160" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-5" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="360" y="70" width="170" height="350" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-6" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="190" y="230" width="150" height="240" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-7" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="540" y="-100" width="110" height="460" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-8" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;category /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeWidth=2;strokeColor=#FF0000;" vertex="1" parent="1">
<mxGeometry x="540" y="370" width="110" height="80" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-10" value="&lt;font style=&quot;font-size: 23px ; background-color: rgb(255 , 255 , 255)&quot;&gt;&amp;lt;location /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#3DFFB1;strokeWidth=2;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="190" y="-151.12" width="460" height="41.12" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-11" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;cities /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=2;fillColor=none;strokeColor=#45C7FF;" vertex="1" parent="1">
<mxGeometry x="670" y="-110" width="80" height="450" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-12" value="&lt;span style=&quot;background-color: rgb(255 , 255 , 255)&quot;&gt;&lt;font style=&quot;font-size: 15px&quot;&gt;&amp;lt;Language /&amp;gt;&lt;/font&gt;&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=2;fillColor=none;strokeColor=#FF9933;" vertex="1" parent="1">
<mxGeometry x="660" y="-151.12" width="90" height="41.12" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-14" value="&lt;font style=&quot;font-size: 23px&quot;&gt;&amp;lt;header /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=#FF9933;strokeWidth=2;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="20" y="-140" width="160" height="220" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-15" value="&lt;font style=&quot;font-size: 20px&quot;&gt;&amp;lt;calendar /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=2;fillColor=none;strokeColor=#FF66FF;" vertex="1" parent="1">
<mxGeometry x="40" y="-20" width="120" height="90" as="geometry" />
</mxCell>
<mxCell id="Pv-lDhROw9vmJ1KCem3l-16" value="&lt;font style=&quot;font-size: 26px&quot;&gt;&amp;lt;links /&amp;gt;&lt;/font&gt;" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=2;fillColor=none;strokeColor=#B266FF;" vertex="1" parent="1">
<mxGeometry x="40" y="85" width="120" height="255" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
123 changes: 123 additions & 0 deletions lib/adagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
require 'csv'

##################### wave 1
def draw_letters
Comment on lines +3 to +4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

letter_pool = []

9.times {letter_pool.push("A", "I")}
2.times {letter_pool.push("B", "C", "F", "H", "M", "P", "V", "W", "Y" )}
4.times {letter_pool.push("D", "L", "S", "U")}
12.times {letter_pool << "E"}
3.times {letter_pool << "G"}
letter_pool << "J"
letter_pool << "K"
6.times {letter_pool.push("N", "R", "T")}
8.times {letter_pool << "O"}
letter_pool.push("Q", "X", "Z")

drawn_letters = letter_pool.sample(10)
return drawn_letters
end

####################### wave 2

def uses_available_letters?(input, letters_in_hand)
input_letters = input.split("")
if input_letters.length > 10
puts "Oops, too many letters! You only have 10 :)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do puts here. Just return false or raise an error. Probably raising an error makes sense here.

Suggested change
puts "Oops, too many letters! You only have 10 :)"

return false
end

if input_letters == input_letters.uniq
if (input_letters - letters_in_hand).empty?
return true
else
return false
end
else
counts_input = input_letters.group_by {|letter| letter}
counts_letterinhand = letters_in_hand.group_by {|letter| letter}
Comment on lines +38 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever use of group_by


counts_input.each_pair do |letter, count|
if counts_input[letter].length > counts_letterinhand[letter].length
puts "Looks like you use #{letter} too many times."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
puts "Looks like you use #{letter} too many times."

return false
end
end

return true
end

end

############################# wave 3
def score_word(word)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

word = word.upcase
input_letters = word.split("")
score = 0
if input_letters.length > 6
score += 8
end

input_letters.each do |letter|

case letter
when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T"
score += 1
when "D", "G"
score += 2
when "B", "C", "M", "P"
score += 3
when "F", "H", "V", "W", "Y"
score += 4
when "K"
score += 5
when "J", "X"
score += 8
when "Q", "Z"
score += 10
end


end

return score
end

######################### wave 4
def highest_score_from(words)
Comment on lines +87 to +88
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice uses of select and max_by.

word_score = {}
words.each do |word|
word_score[word] = score_word(word)
end
winner_random = word_score.max_by {|word, score| score}
winner_random[0] = winner_random[0].to_s

winner_all = word_score.select {|word, score| score == winner_random[1]}
winner_final = {}

if winner_all.length > 1
ten_letter_words = winner_all.select {|word, score| word.size == 10}
if ten_letter_words.empty?
winner_final_candidates = winner_all
else
winner_final_candidates = ten_letter_words
end

winner_final[:word], winner_final[:score] = winner_final_candidates.min_by{|word, score| word.length}
else
winner_final[:word] = winner_all.keys.join
winner_final[:score] = winner_all.values.join.to_i
end

return winner_final

end

######################### wave 5
def is_in_english_dict?(input)
Comment on lines +117 to +118
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, you got the optional dictionary!


dictionary = CSV.read('../assets/dictionary-english.csv').map { |word| word.to_s }
return dictionary.include?(input)

end