Skip to content

Instantly share code, notes, and snippets.

@luthfianto
Created March 22, 2014 14:07
Show Gist options
  • Save luthfianto/9707717 to your computer and use it in GitHub Desktop.
Save luthfianto/9707717 to your computer and use it in GitHub Desktop.
A bad implementation of Soundex in Julia. Not sure if its working though
function soundex(s::String)
const head = lowercase(s[1])
const tail = lowercase(s[2:end])
const dict= [ "a"=>"", "e"=>"", "i"=>"", "o"=>"", "u"=>"", "y"=>"", "h"=>"", "w"=>"", "b"=>"1", "f"=>"1", "p"=>"1", "v"=>"1", "c"=>"2", "g"=>"2", "j"=>"2", "k"=>"2", "q"=>"2", "s"=>"2", "x"=>"2", "z"=>"2", "d"=>"3", "t"=>"3", "l"=>"4", "m"=>"5", "n"=>"5", "r"=>"6"]
const t=split(tail,"")
const t1=map(x->dict[x],t)
output=ASCIIString[]
prev=""
index=0
for c in t1
if c!=prev
prev=c
append!(output,[c])
end
index+=1
end
return string( uppercase(head),join(output), "0000")[1:4]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment