Skip to content

Instantly share code, notes, and snippets.

@Ikhan
Created April 4, 2016 22:20
Show Gist options
  • Save Ikhan/593b272e30d8eeb5d8f078be2560e9f3 to your computer and use it in GitHub Desktop.
Save Ikhan/593b272e30d8eeb5d8f078be2560e9f3 to your computer and use it in GitHub Desktop.
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')
@Ikhan
Copy link
Author

Ikhan commented Apr 17, 2016

You can download the anagrams this link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment