Anagrams: Difference between revisions
Content added Content deleted
(Updated the Crystal code to avoid Nil reference error) |
|||
Line 1,825: | Line 1,825: | ||
response = HTTP::Client.get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") |
response = HTTP::Client.get("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") |
||
if response.body? |
|||
words : Array(String) = response. |
words : Array(String) = response.body.split |
||
anagram = {} of String => Array(String) |
anagram = {} of String => Array(String) |
||
words.each do |word| |
words.each do |word| |
||
key = word.split("").sort.join |
key = word.split("").sort.join |
||
if !anagram[key]? |
if !anagram[key]? |
||
anagram[key] = [word] |
anagram[key] = [word] |
||
else |
else |
||
anagram[key] << word |
anagram[key] << word |
||
end |
|||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
⚫ | |||
</lang> |
</lang> |
||
Line 1,852: | Line 1,854: | ||
["evil", "levi", "live", "veil", "vile"] |
["evil", "levi", "live", "veil", "vile"] |
||
</pre> |
</pre> |
||
== {{header|D}} == |
== {{header|D}} == |