From: Martin DeMello Date: 2004-12-20T05:42:06+09:00 Subject: [QUIZ][SOLUTION] Scrabble Stems (#12) Here's my solution. I used the sowpods wordlist available here: http://www.isc.ro/commands/lists.html (preprocessed to be all-lowercase, though it doesn't really matter as long as the case is consistent). It takes entirely too long to run (12 seconds on my P4/3GHz); I'll poke at it some more if I get the time and see what's slowing it down. -------------------------------------------------------------------------- $stems = {} $seen = {} $cutoff = ARGV[0].to_i IO.foreach("sowpods.txt") {|word| next if word.length != 8 word.chomp! letters = word.split(//).sort alpha = letters.join next if $seen[alpha] $seen[alpha] = true remove = letters.uniq remove.each {|i| stem = alpha.sub(i, '') $stems[stem] ||= {} $stems[stem][i] = true } } $stem_length = {} $stems.each {|k,v| $stems[k] = v.keys.sort} $stems.reject! {|k,v| n = v.length $stem_length[k] = n n < $cutoff } results = $stems.keys.sort_by {|i| -$stem_length[i]} results.each {|s| p [s, $stem_length[s], $stems[s].join]}