Created
June 22, 2022 16:07
-
-
Save ImaginaryDevelopment/489ccefcf5064847df153452a44ec226 to your computer and use it in GitHub Desktop.
a Fibonacci with unfold up to 4mil for euler
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
let fib x = | |
(0,0) | |
|> Seq.unfold(fun (a,b) -> | |
match a,b with | |
| 0, 0 -> Some(1, (0, 1)) | |
| _ -> | |
let c = a + b | |
Some(c, (b,c)) | |
) | |
|> Seq.indexed | |
|> Seq.map(fun (i,x) -> i+1, x) | |
|> Seq.takeWhile(fun (i,v) -> i <= x && v < 4_000_000) | |
|> Seq.last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment