MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1y3320n/dynamicprogramming/19t3ddavl8ns1/?context=3
r/ProgrammerHumor • u/nerdycatgamer • 1d ago
140 comments sorted by
View all comments
Show parent comment
1
const root5 = Math.sqrt(5); const phi = (1 + root5) / 2; const psi = (1 - root5) / 2; function fib(n) { return (Math.pow(phi, n) - Math.pow(psi, n)) / root5; }
Closed-form Fibonacci expression. O(1) if you ignore that exponentiation isn't constant time.
0 u/donaldhobson 11h ago And if you ignore that floating point errors cause problems at n=70.Whereas I was using python, which has arbitrary size ints.
0
And if you ignore that floating point errors cause problems at n=70.
Whereas I was using python, which has arbitrary size ints.
View all comments
Show parent comment
1
u/Lithl 22h ago
Closed-form Fibonacci expression. O(1) if you ignore that exponentiation isn't constant time.