find all multiplicands and multipliers for a number

Paul Rubin no.email at nospam.invalid
Wed Apr 15 12:21:14 EDT 2015


Ian Kelly <ian.g.kelly at gmail.com> writes:
> Nope. You do end up with a lot of nested filter objects, but there's
> no recursion in the Python code, which means that you're not piling up
> frame objects, and you'll never hit the interpreter's recursion limit.

I think you do get frame objects.  A quick experiment:

 def d(fuel):
	f = lambda x:x
	for i in range(fuel): f = lambda x,g=f: 1+g(x)
	return f

    >>> d(3)
    <function <lambda> at 0x1a3b9b0>
    >>> d(100)(0)
    100
    >>> d(1000)(0)

    Traceback (most recent call last):
      File "<pyshell#24>", line 1, in <module>
        d(1000)(0)
      File "<pyshell#20>", line 3, in <lambda>
        for i in range(fuel): f = lambda x,g=f: 1+g(x)
      File "<pyshell#20>", line 3, in <lambda>
      [ 1000's of lines snipped ]
    RuntimeError: maximum recursion depth exceeded
    >>> 

This happens in both 2.7 and 3.3.4.



More information about the Python-list mailing list