Recursion and Variable Scope
Ignacio Vazquez-Abrams
ignacio at openservices.net
Fri Sep 7 10:35:15 EDT 2001
On Fri, 7 Sep 2001, Ignacio Vazquez-Abrams wrote:
> Here's your Evil Generator of Death:
>
> ---
> def generator(sides, dice):
> if dice==1:
> return map(lambda x: [x], range(1, sides+1))
> else:
> import operator
> return reduce(operator.add, map(eval("lambda y: eval('map(lambda x: [x]+%%s, range(1, %%s+1))' %% (y,%s))" % sides), generator(sides, dice-1)))
> ---
And here's it's cohort, the Malevolent Generator of Doom:
---
def generator(s, d):
return map(eval('lambda y:map(eval("lambda x: 1+((%%s/(long(%%s)**x)) %%%% %%s)" %% (y, %s, %s)), range(%s))' % (s, s, d)), xrange(long(s)**d))
---
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list