News for hackers. Stuff that matters.
Re:It Can Happen to You by astine on Wednesday March 03, 2021 @09:02PM (#26337675)
And now your memory usage will grow eye-wateringly large. Instead, convert the algorithm to be iterative or at least tail-recursive and it will be faster than both the naive and memoized versions!
Re:It Can Happen to You by karamazov on Wednesday March 03, 2021 @09:03PM (#26337688)
Or use the closed-form solution.
Re:It Can Happen to You by jacobolus on Wednesday March 03, 2021 @09:39PM (#26337947)
The "closed-form solution" is slower than standard method. It just uses arbitrary-precision fractional arithmetic (square root, exponentiation, division) instead of arbitrary-precision integer arithmetic (exponentiation of a 2x2 integer matrix).
Re:It Can Happen to You by singhrac on Wednesday March 03, 2021 @09:53PM (#26338042)
The best solution is to use the O(log n) time exponentiation of a matrix, which is fast enough to be constant.