# Project Euler Problem 14

Project Euler Problem 14 can be addressed “as is”:

- for any number we can build a sequence by the given rules and measure its length
- for each number from the given range we build correspondent sequences and aggregate by finding the number producing the longest sequence

let numTerms (n: int64) = Seq.unfold (fun x -> if x = 1L then None elif x%2L = 0L then Some(x, x/2L) else Some(x, 3L*x + 1L)) n |> Seq.length |> fun x -> (n, x+1) let problem014 () = [1L..999999L] |> List.map numTerms |> (List.maxBy snd >> fst)

Advertisements

Leave a Comment