Skip to content

Instantly share code, notes, and snippets.

@ImaginaryDevelopment
Created June 22, 2022 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ImaginaryDevelopment/489ccefcf5064847df153452a44ec226 to your computer and use it in GitHub Desktop.
Save ImaginaryDevelopment/489ccefcf5064847df153452a44ec226 to your computer and use it in GitHub Desktop.
a Fibonacci with unfold up to 4mil for euler
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