Skip to content

Instantly share code, notes, and snippets.

@Arthraim
Created December 26, 2012 17:52
Show Gist options
  • Save Arthraim/4381784 to your computer and use it in GitHub Desktop.
Save Arthraim/4381784 to your computer and use it in GitHub Desktop.
King of Letterpress
# find words in letters
words = ["abc", "def"] # you need a biiiiiiiiiiig word list here
letters = "pfwbsubarciesgqwjfornotyl"
results = []
words.each do |w|
dict = letters.split //
flag = true
(w.split //).each do |l|
#p dict
if (dict.include? l)
i = dict.index l
dict.delete_at i
#p "deleted " + l
else
flag = false
break
end
end
results.push w if flag
end
p results.sort{|x, y| y.length <=> x.length}
# really violence huh?
# I don't know if regex can do this with one single expression :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment