Last active
December 21, 2015 02:29
-
-
Save porterjamesj/6235524 to your computer and use it in GitHub Desktop.
longest anagram finder in julia
This file contains 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
function doit(f::IOStream) | |
wordmap = Dict{Array{Char},Array{Char}}() | |
best = (0,"","") | |
for line in eachline(f) | |
if length(line) > best[1] | |
word = collect(line) | |
cannonical = sort(word) | |
if haskey(wordmap,cannonical) | |
best = (length(word),word,wordmap[cannonical]) | |
else | |
wordmap[cannonical] = word | |
end | |
end | |
end | |
return best | |
end | |
f = open("sowpods.txt","r") | |
best = doit(f) | |
println(best) | |
f = open("sowpods.txt","r") | |
@time doit(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment