gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [gforth] naive fibonacci


From: Dennis Ruffer
Subject: RE: [gforth] naive fibonacci
Date: Sat, 6 Mar 2010 18:36:37 -0800

> -----Original Message-----
> From: address@hidden [mailto:gforth-
> address@hidden On Behalf Of Terrence Brannon
> But I would like to know why mine does not work:
> 
> : fib { n -- fibn }
>   assert( n 0>= )
>   n CASE
>     0 OF 0 ENDOF
>     1 OF 1 ENDOF
>     2 OF 1 ENDOF
>     ( otherwise ) n 1 - recurse n 2 - recurse +
>   ENDCASE ;

Remember that n is left on the stack after the last ENDOF, so you end up
putting it on again.

Not sure why you want 2 recurse's either or the other n 2 -.

I can't follow the logic, but then the people in that shootout are much
better at it than I am. ;)

DaR








reply via email to

[Prev in Thread] Current Thread [Next in Thread]