Skip to content

Project Euler Problem 14

October 26, 2011

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

  1. for any number we can build a sequence by the given rules and measure its length
  2. 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

From → Project Euler

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: