LeetCode 1502. Can Make Arithmetic Progression From Sequence in F#
URL
Can Make Arithmetic Progression From Sequence - LeetCode
Code
https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/1502/main.fsx
let canMakeArithmeticProgression (arr: int list) : bool =
let diffs =
arr
|> List.sort
|> List.windowed 2
|> List.map (fun v ->
match v with
| a1 :: a2 :: [] -> a2 - a1
| _ -> failwith "never reach here")
let diff = List.head diffs
List.forall (fun a -> a = diff) diffs