06-05-2019 08:24 AM
Okay, a Leonardo of Pisa Challenge -- Write a function that takes an integer N and returns Fib (N) using the slightly-revised defintion:
Fib (N) = 0, N <= 0
Fib (N) = 1, N = 1
Fib (N) = Fib (N-1) + Fib (N-2) otherwise.
Return Fib (N) without internally calculating and saving Fib (1), Fib (2), ... Fib (N-1) -- use only the definition above for Fib (N).
Warning -- the size of Fib (N) and the time to compute it (under the terms above) increase exponentially with time. Hint -- Wiebe.
Test Fib (N)
Bob Schor
06-05-2019 08:36 AM
wiebe@CARYA wrote:
I'd do recursion:
When I said that, I mend "I'd do recursion to impress the teacher"... Otherwise, pick the simplest solution.
06-05-2019 08:40 AM - edited 06-05-2019 08:41 AM
@jamiva wrote:
Here is another implementation without any case structures or BuildArrays. Works for F0, F1,... to F93
I'd prefer the Min & Max with 93 over the In Range and Coerce. The results would still be valid for <0, AFAIC.
Other then that, I don't think it will get much better.
06-05-2019 08:53 AM
@Bob_Schor wrote:
Okay, a Leonardo of Pisa Challenge -- Write a function that takes an integer N and returns Fib (N) using the slightly-revised defintion:
Fib (N) = 0, N <= 0
Fib (N) = 1, N = 1
Fib (N) = Fib (N-1) + Fib (N-2) otherwise.
Return Fib (N) without internally calculating and saving Fib (1), Fib (2), ... Fib (N-1) -- use only the definition above for Fib (N).
This might be cheating... Not sure which rule I broke though.
06-05-2019 09:51 AM
Thanks!
I will improve
06-05-2019 10:10 AM
I'd say y = 0,4414e0,4817x for x>=2
/Y
06-05-2019 10:18 AM
Wiebe -- You 'da Man! I didn't think to bring out Fib (N-1) as a "helper" output (which accounts for the exponential Time of my code, and the incredible speed of yours). I love recursion, though it does have traps "for the unwary" (such as I).
Bob Schor
06-05-2019 10:22 AM
06-05-2019 10:22 AM - edited 06-05-2019 10:28 AM
@Bob_Schor wrote:
Wiebe -- You 'da Man! I didn't think to bring out Fib (N-1) as a "helper" output (which accounts for the exponential Time of my code, and the incredible speed of yours). I love recursion, though it does have traps "for the unwary" (such as I).
Bob Schor
So I didn't cheat ?
(It actually freaked me out a bit that it worked.)
06-05-2019 10:23 AM
don't forget about the infamous formula node