learning F#, it seems pretty cool, favourite functional language so far.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Hamming.fs 314B

12345678
  1. module Hamming
  2. let hamming s1 s2 =
  3. let pairs = Seq.zip s1 s2
  4. Seq.fold (fun a x -> if (x |> fst) <> (x |> snd) then (a + 1) else a) 0 pairs
  5. let distance (strand1: string) (strand2: string): int option =
  6. if String.length strand1 <> String.length strand2 then None else Some(hamming strand1 strand2)