Skip to content

Instantly share code, notes, and snippets.

@CJKinni
Created August 8, 2012 20:39
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 CJKinni/3298503 to your computer and use it in GitHub Desktop.
Save CJKinni/3298503 to your computer and use it in GitHub Desktop.
Anagram Solver
#/usr/bin/ruby
## Name data from http://www.ssa.gov/oact/babynames/limits.html
## Originally used on 8 Aug to find an anagram of a name. Neural.
FILENAME = "/Users/ckinniburgh/Dropbox/Development/AnagramSolver/yob1991.txt"
puts "Input anagram: "
STDOUT.flush
anagram = gets.chomp
puts "Finding an anagram for " + anagram + "."
anagramArray = anagram.downcase.scan(/./).sort!
f = File.open(FILENAME) or die "Where's your file? I sure can't find and open it."
f.each_line { |line|
testName = line.split(/,/)[0].downcase.scan(/./).sort!
if testName == anagramArray
puts line
end
}
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment