AgreeableLandscapeM to Programmer Humor · 3 years agoThe O(1) Fibonacci implementationimagemessage-square8fedilinkarrow-up162arrow-down14
arrow-up158arrow-down1imageThe O(1) Fibonacci implementationAgreeableLandscapeM to Programmer Humor · 3 years agomessage-square8fedilink
minus-squareAbbélinkfedilinkarrow-up1·3 years agoghci> φ = (1 + sqrt 5) / 2 ghci> ψ = 1 - φ ghci> fib n = (φ ** n - ψ ** n) / (sqrt 5)
ghci> φ = (1 + sqrt 5) / 2 ghci> ψ = 1 - φ ghci> fib n = (φ ** n - ψ ** n) / (sqrt 5)