Iteration for Factorials
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Oct 30 22:20:37 EDT 2007
En Tue, 30 Oct 2007 15:37:57 -0300, mensanator at aol.com
<mensanator at aol.com> escribió:
> On Oct 30, 10:25 am, "J. Clifford Dyer" <j... at sdf.lonestar.org> wrote:
>> The great part about this recursive solution is that you don't have to
>> worry about the stack limit because performance degrades so quickly on
>> the conversion to string! fact(8) takes a little less than a second,
>> fact(9) takes about a minute, and fact(10) takes more time than I had
>> patience to wait for!
>
> And the not-so-great part is that it raises an exception
> on fact(0) which makes it utterly useless for calculating
> combinations of m things taken n at a time: m!/n!*(m-n)!
>
> Why is it that no one seems able to get this right?
Uhmmm... don't be so serious, most of those recipes are a joke :)
Who cares about fact(0) when fact(10) can't be computed...? At least,
that's how I see it, Nimo dixit.
--
Gabriel Genellina
More information about the Python-list
mailing list