Here's one version
let totalManhattanDistance board goal =
let manhattanDistance ((x1, y1), (x2, y2)) = abs(x1 - x2) + abs(y1 - y2)
let indexed xs = xs |> Seq.mapi (fun i -> Seq.mapi (fun j x -> (i, j), x))
|> Seq.concat
|> Seq.sortBy snd
|> Seq.map fst
Seq.zip (indexed board) (indexed goal)
|> Seq.map manhattanDistance
|> Seq.sum
The three Seq operations in the end could be done with just one Array.fold2 but I don't know if this makes the code any clearer
let totalManhattanDistance board goal =
let manhattanDistance (x1, y1) (x2, y2) = abs(x1 - x2) + abs(y1 - y2)
let indexed xs = xs |> Array.mapi (fun i -> Array.mapi (fun j x -> (i, j), x))
|> Array.concat
|> Array.sortBy snd
|> Array.map fst
let folder = fun acc n m -> acc + manhattanDistance n m
Array.fold2 folder 0 (indexed board) (indexed goal)