On Jul 13, 8:44 pm, Fuzzyman <[EMAIL PROTECTED]> wrote:
> On Jul 13, 7:56 am, Steven D'Aprano <[EMAIL PROTECTED]
>
>
>
> cybersource.com.au> wrote:
> > On Sat, 12 Jul 2008 19:25:18 -0400, Terry Reedy wrote:
> > > ssecorp wrote:
> > >> def fib(n):
> > >> def fibt(a, b, n):
> > >> if n <=
On Jul 13, 7:56 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sat, 12 Jul 2008 19:25:18 -0400, Terry Reedy wrote:
> > ssecorp wrote:
> >> def fib(n):
> >> def fibt(a, b, n):
> >> if n <= 1:
> >> return b
> >> else:
> >> return fib
On Sat, 12 Jul 2008 19:25:18 -0400, Terry Reedy wrote:
> ssecorp wrote:
>> def fib(n):
>> def fibt(a, b, n):
>> if n <= 1:
>> return b
>> else:
>> return fibt(b, a + b, n - 1)
>> if n == 0:
>> return 0
>> else:
>> return fibt(0, 1
ssecorp wrote:
def fib(n):
def fibt(a, b, n):
if n <= 1:
return b
else:
return fibt(b, a + b, n - 1)
if n == 0:
return 0
else:
return fibt(0, 1, n);
and can memoization speed up this even more? tesintg with memoization
doesnt
ssecorp wrote:
used>
and can memoization speed up this even more?
Generators get you to an even clearer Fibonacci expression.
def _Fibonacci_gen():
a, b = 1, 0
while True:
a += b
yield a
b += a
yield b
Here's how to use
ssecorp <[EMAIL PROTECTED]> asked:
> Why is this blowing the stack, thought it was tail-recursive...
Because python does no tail-call optimization.
Ciao
Marc
--
http://mail.python.org/mailman/listinfo/python-list