Skip to content

Instantly share code, notes, and snippets.

@porterjamesj
Last active December 21, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save porterjamesj/6235524 to your computer and use it in GitHub Desktop.
Save porterjamesj/6235524 to your computer and use it in GitHub Desktop.
longest anagram finder in julia
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