Created
April 4, 2016 22:20
-
-
Save Ikhan/593b272e30d8eeb5d8f078be2560e9f3 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
def anagrams(n) | |
text = File.open('words.txt').read | |
candidates = [] | |
text.each_line do |line| | |
if (line.length - 1) == n.length | |
candidates << line.gsub("\n",'') | |
end | |
end | |
result = [] | |
candidates.each do |word| | |
if word.chars.sort == n.chars.sort | |
result << word | |
end | |
end | |
p result | |
end | |
anagrams('horse') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can download the anagrams this link