Files
2025-08-03 20:16:55 -07:00

16 lines
403 B
FSharp

module _14
let collatzConjecture n =
match n with
| 0L -> None
| 1L -> Some(1L,0L)
| n -> Some(n,
if n % 2L = 0L then n/2L
else if n % 2L = 1L then 3L*n + 1L
else 1L)
let getLongestChain =
[1L..1000000L]
|> Seq.map (fun i -> (i |> Seq.unfold collatzConjecture |> Seq.length, i))
|> Seq.max