Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fibonacci

Name: Anonymous 2008-04-21 14:38

Hi

I need some help with calculating Fibonacci
N is an output that shows the Fibonacci numbers

-- Begin
N <= 0 -> N=1 A=1 B=1 C=1 D=1;
N=A+B
C=N
N=B+C
D=N
N=C+D
B=N
N=D+B
A=N
-- Restart at begining

Any idea what I did wrong? I can't figure it out

Name: Anonymous 2008-04-21 15:47

I don't understand what you wrote but here is the iterative version. fib(n) gives the nth fibonacci number.

fib(n) = f(n,1,0) where
f(m,a,b) = b if m=0 else f(m-1,a+b,a)

Name: Anonymous 2008-04-22 14:16

It something I wrote for WiRE. That language does not support fib(n)

Name: Anonymous 2008-04-22 15:24

I'm not familiar with WiRE. At what points are you printing out N? When do you stop? Why have you defined all your variables inside the loop? Won't it just reset each time?

What's wrong with:

N=1, A=1, B=1
-- begin
N = A + B
output N
A = B
B = N
-- restart

All >>2 is doing, is defining a function fib(n)

Name: Anonymous 2008-04-23 2:22

>>4
Thanks, I'll try this one out tonight

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List