Last active
December 30, 2015 23:59
-
-
Save quicksnap/7904049 to your computer and use it in GitHub Desktop.
Faster!
This file contains hidden or 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/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