[Tutor] fibonacci

Jayprasad J. Hegde jjhegde@konark.ncst.ernet.in
Fri Feb 14 03:22:02 2003


On Wed, Feb 12, 2003 at 07:51:33PM +1100, Alfred Milgrom wrote:
[ snip ] 
> 
> Just as an exercise, I was unable to create a one-line recursive fibonacci 
> generator, but the following works correctly for all values of n greater 
> than 2.
> 
> def fib(n):
>     return (n<5)*(n-2) or fib(n-1) + fib(n-2)

I would not recommend creating a second order (containing two recursive elements e.g. "fib (n - 1)" and  "fib (n - 2)" ) recursive function like this. 
It would be best if you can find...
1. a recursive function with a single recursive element, or
2. sticking to an iterative variant. 

regards
- JJH
-- 
(defun JJHdetails ()
  (format t "~&~A~&~A~&~A"
    "Jayprasad J Hegde, KBCS, NCST" "Gulmohar Cross
    Road 9, Juhu, Mumbai 400049." "tel: +91-22-26201606x373"))