Skip to content

Instantly share code, notes, and snippets.

@heavysixer
Created December 12, 2012 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heavysixer/c3129ba0a6cd9b12fd8c to your computer and use it in GitHub Desktop.
Save heavysixer/c3129ba0a6cd9b12fd8c to your computer and use it in GitHub Desktop.
# 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