aleax at aleax.it
Thu Jan 24 16:31:46 CET 2002
<arthur.siegel at rsmi.com> wrote in message
news:mailman.1011811475.724.python-list at python.org...
> I'd propose the following as "simplest" - in the
> sense of the code reflecting a naive
> understanding of the concept, and fundametal
> programming operations with no magic.
> Am I missing the handling of some degenerate
Yes, in a sense -- in Python 2.1 and earlier, all
strings of length 13 or more will cause an overflow
in one of the multiplications, since 12! is the
largest factorial that fits in a 32-bit signed
integer (assuming your machine is 32-bit -- you'll
be able to handle slightly longer strings if you
have a 64-bit machine).
No problem in Python 2.2 (it gives a long result
rather than an overflow) and easily fixed in earlier
> def f(s):
Just change this initialization to x=1L (thus ensuring
a long result anyway) and it will work.
More information about the Python-list