Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 685 Bytes

README.md

File metadata and controls

22 lines (20 loc) · 685 Bytes

elm levenstein

leven: String -> String -> Int
leven s1 s2 =
    if String.length s1 == 0 then
            String.length s2
    else if String.length s2 == 0 then
            String.length s1
    else 
          if right 1 s1 == right 1 s2 then
            leven (dropRight 1 s1) (dropRight 1 s2) -- 右端の文字が同じなら切り捨て
          else
            Maybe.withDefault 0
            (List.minimum [leven (dropRight 1 s1) s2,
                  leven s1 (dropRight 1 s2),
                  leven (dropRight 1 s1) (dropRight 1 s2)]) + 1