ssecorp wrote:
<a recursive Fibonacci generator thast demonstrates no tail recursion 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 it to avoid redundant comutation:

    _next_entry = _Fibonacci_gen().next
    _sofar = []

    def fib(n):
        while len(_sofar) <= n:
            _sofar.append(_next_entry())
        return _sofar[n]


--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to