Created
August 8, 2012 20:39
-
-
Save CJKinni/3298503 to your computer and use it in GitHub Desktop.
Anagram Solver
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
#/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