Would like to know if this would be a valuable addition as an Approach in mentioned F# exercise?
If so, I can add a PR.
let distance (strand1: string) (strand2: string) : int option =
if strand1.Length <> strand2.Length
then None
else
[ for idx in 0 .. strand1.Length - 1 do
yield strand1[idx] <> strand2[idx] ]
|> List.sumBy Convert.ToInt32
|> Some
I like the idea of having an approach with a list comprehension. Personally, I’m not a fan of converting booleans to integers, that to me feels a more suitable to low-level languages like C or dynamic languages like Python.
let distance (strand1: string) (strand2: string) : int option =
if strand1.Length <> strand2.Length
then None
else
[ for idx in 0 .. strand1.Length - 1 do
yield if strand1[idx] = strand2[idx] then 0 else 1 ]
|> List.sum
|> Some
I’d be happy to have a separate section in the approach that showcases Convert.ToInt32, but I am hesitant to make the core code of the approach.