Skip to content

Commit

Permalink
finally read the specs for the "Grow words from fertile vocabularies"…
Browse files Browse the repository at this point in the history
… challenge
  • Loading branch information
clupasq committed Jan 30, 2015
1 parent abbd5bd commit 88f3fdc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions longest_word_by_appending_letters/longest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

h={}
open('voc').map{|l|h[l.strip]=1}
v=->w{w<?a||h[w]&&(v[w.chop]||v[w[1..-1]])}
p h.keys.max_by{|w|w.size*(v[w]?1:0)}
v=->w,c=[]{w<?a?c:h[w]&&(v[w.chop,z=c+[w]]||v[w[1..-1],z])}
puts h.map{|k,_|(v[k]||[]).reverse.join ?\n}.max_by &:size

# p h.keys.select{|w|v[w]}.compact.first 10


=begin
Expand Down

0 comments on commit 88f3fdc

Please sign in to comment.