Skip to content

Instantly share code, notes, and snippets.

@follesoe
Last active December 22, 2015 00:18
Show Gist options
  • Save follesoe/6387816 to your computer and use it in GitHub Desktop.
Save follesoe/6387816 to your computer and use it in GitHub Desktop.
Find variable length anagrams based on dictionary
words = Hash.new([])
File.open("words.txt", "r") do |file|
while line = file.gets
word = line.chomp.downcase
words[word.split('').sort!.join('')] += [word]
end
end
File.open("names.txt", "r") do |file|
while line = file.gets
names = line.downcase.chomp.split(' ')
names.each do |name|
puts "Navn: #{name}"
combinations = []
for counter in 3..name.length
name.split('').combination(counter).each do |comb|
combinations << comb.sort!
end
end
combinations.each do |combo|
words[combo.join('')].each do |anagram|
puts "\t#{anagram}"
end
end
end
end
end
@heim
Copy link

heim commented Aug 30, 2013

maskin

@heim
Copy link

heim commented Aug 30, 2013

💩

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