Created
December 26, 2012 17:52
-
-
Save Arthraim/4381784 to your computer and use it in GitHub Desktop.
King of Letterpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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