Skip to content

Instantly share code, notes, and snippets.

@swarley
Created March 9, 2013 01:58
Show Gist options
  • Save swarley/5122142 to your computer and use it in GitHub Desktop.
Save swarley/5122142 to your computer and use it in GitHub Desktop.
require "trie"
trie = Trie.new
dict = {}
File.open("/usr/share/dict/american-english") do |f|
lines = f.read.split("\n")
lines.map(&:chomp).each {|word| (dict[word.size]||=Trie.new).add word, 1 }
end
letters = "psylyrcytyrglhltyprpsyyssysty"
perm3l = letters.split('').permutation(3).to_a.keep_if {|x| x.include? 'y' }.map! {|x| x.inject(:+) }
dict3l = perm3l.select {|x| dict[3].has_key? x }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment