Skip to content

Instantly share code, notes, and snippets.

@quicksnap
Last active December 30, 2015 23:59
Show Gist options
  • Select an option

  • Save quicksnap/7904049 to your computer and use it in GitHub Desktop.

Select an option

Save quicksnap/7904049 to your computer and use it in GitHub Desktop.
Faster!
#!/usr/bin/env ruby
file = File.open("/usr/share/dict/words")
def splitSortJoin(line)
line.chomp.split('').sort
end
line_map = {}
match_keys = []
file.each_line do |line|
line = line.chomp
key = line.split('').sort.join
line_map[key] ||= []
line_map[key] << line
if line_map[key].length > 1
match_keys << key
end
end
match_keys.each do |key|
line_map[key].each { |word| puts "#{word}" }
puts "--"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment