Anagrams: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,470: | Line 3,470: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<lang Julia>url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt" |
<lang Julia>url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt" |
||
wordlist = open(readlines, download(url)) |
wordlist = open(readlines, download(url)) |
||
wsort(word) = join(sort(collect(word))) |
wsort(word::AbstractString) = join(sort(collect(word))) |
||
function anagram(wordlist) |
function anagram(wordlist::Vector{<:AbstractString}) |
||
dict = Dict{String, Set{String}}() |
|||
for word in wordlist |
for word in wordlist |
||
sorted = wsort(word) |
sorted = wsort(word) |
||
push!(get!(dict, sorted, Set{String}()), word) |
|||
⚫ | |||
ananum = max(length(hash[sorted]), ananum) |
|||
wcnt = maximum(length, values(dict)) |
|||
⚫ | |||
collect( |
return collect(Iterators.filter((y) -> length(y) == wcnt, values(dict))) |
||
end |
end |
||
</lang> |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>Set(String["live", "vile", "veil", "evil", "levi"]) |
|||
⚫ | |||
⚫ | |||
6-element Array{Any,1}: |
|||
Set(String["crate", "cater", "carte", "trace", "caret"]) |
|||
Set(String["galen", "angel", "lange", "angle", "glean"]) |
|||
Set(String["lager", "regal", "glare", "large", "alger"]) |
|||
Set(String["neal", "elan", "lena", "lane", "lean"])</pre> |
|||
⚫ | |||
Any["caret","carte","cater","crate","trace"]</pre> |
|||
=={{header|K}}== |
=={{header|K}}== |