ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array with Fibonacci numbers

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)Test Fib (N)

Bob Schor

Message 21 of 30
(2,508 Views)

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.

0 Kudos
Message 22 of 30
(2,500 Views)

@jamiva wrote:

Here is another implementation without any case structures or BuildArrays. Works for F0, F1,... to F93

 

FibonacciSeries.png


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.

0 Kudos
Message 23 of 30
(2,500 Views)

@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.

0 Kudos
Message 24 of 30
(2,492 Views)

Thanks! 

I will improve  Smiley Happy

0 Kudos
Message 25 of 30
(2,478 Views)

I'd say y = 0,4414e0,4817x for x>=2

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 26 of 30
(2,467 Views)

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

0 Kudos
Message 27 of 30
(2,461 Views)

@Yamaeda wrote:

I'd say y = 0,4414e0,4817x for x>=2

/Y


nice

yameda.png

0 Kudos
Message 28 of 30
(2,457 Views)

@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 Smiley Surprised?

 

(It actually freaked me out a bit that it worked.)

0 Kudos
Message 29 of 30
(2,454 Views)

don't forget about the infamous formula node

 

formula-fibionacci.png

 

0 Kudos
Message 30 of 30
(2,452 Views)