recursion - iteration - generator

Notices and updates
Locked
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

recursion - iteration - generator

Post by Lutz »

A new entry on the http://newlisp.org/index.cgi?Tips_and_Tricks page comparing 3 solutions to recursive problems.

Lutz

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Post by rickyboy »

Nice, but 'fibr' and 'fib' are not doing the same thing. 'fibr' returns the nth Fibonacci number and 'fib' returns a partial Fibonacci sequence.

Also, as you well know, one can write a "memoized" version of the recursive function using the idea you incorporated in the generator version.

I like the idea of comparing methods for doing such things, so thank you very much for writing that.
(λx. x x) (λx. x x)

aron
Posts: 8
Joined: Fri May 12, 2006 2:28 am
Location: Sweden
Contact:

Post by aron »

Thanks, i like those, starting to learn these thing now I think.

;; javascript: for(i=0,j=1,k=0,fib=1; i<10; i++,fib=j+k,k=j,j=fib) document.write(fib + " ");
newLISP browser: (print (replace "<[^>]*>" (get-url (read-line)) "" 0))

Locked