AgreeableLandscape@lemmy.mlM to Programmer Humor@lemmy.ml · 3 years agoThe O(1) Fibonacci implementationlemmy.mlimagemessage-square6fedilinkarrow-up143arrow-down13
arrow-up140arrow-down1imageThe O(1) Fibonacci implementationlemmy.mlAgreeableLandscape@lemmy.mlM to Programmer Humor@lemmy.ml · 3 years agomessage-square6fedilink
minus-squareishigami_san@lemmy.mllinkfedilinkarrow-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)