-
-
Save heavysixer/c3129ba0a6cd9b12fd8c to your computer and use it in GitHub Desktop.
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
# Impress your friends with your letterpress skillz through the power of Ruby, and the unix dictionary. | |
# You need to run this in Ruby 1.8.7 | |
# @heavysixer 2012 | |
def anagramify(str) | |
anagrams = [] | |
chars = str.downcase.split(//) | |
`cat /usr/share/dict/words`.each{|word| | |
copy = word.strip!.downcase | |
chars.each {|o| copy.slice!(o) } | |
anagrams.push word.downcase if copy=="" | |
} | |
return anagrams.uniq | |
end | |
puts "Enter a string of letters from the game board." | |
ARGF.each {|line| | |
puts "anagramifying..." | |
anagrams = anagramify(line) | |
puts "sorted alphabetically" | |
puts anagrams.sort{|a,b| b <=> a }.join(" ") | |
puts "sorted by size" | |
puts anagrams.sort{|a,b| b.size <=> a.size}.join(" ") | |
puts "There are #{anagrams.size} partial or full anagrams." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment