Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.