Last active
March 30, 2016 21:00
-
-
Save monkeygroover/41e367beab92ee1d099c to your computer and use it in GitHub Desktop.
euler14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//n → n/2 (n is even) | |
//n → 3n + 1 (n is odd) | |
let collatzSeq = Seq.unfold (fun n -> match n with | |
| 0L -> None | |
| 1L -> Some(1L, 0L) | |
| n -> Some(n, if n % 2L = 0L then n/2L else 3L*n+1L) ) | |
let r = {1L..999999L} |> Seq.map(fun i -> (i, Seq.length(collatzSeq(i)))) |> Seq.maxBy(fun (i,s) -> s) | |
printfn "%A" r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment