Factorials

Phil Weldon pweldon at mindspring.com
Sat Sep 20 00:10:08 EDT 2003


Even faster is a look-up table with what, seventy entries?   That would go
up to an integer with 100 digits, probably more than any application would
need, and certainly the fastest possible method.

Phil Weldon, pweldon at minspring.com

"Andrew Wilkinson" <ajw126 at NOSPAMyork.ac.uk> wrote in message
news:3ee1fa98$0$45181$65c69314 at mercury.nildram.net...
> Rogue9 wrote:
>
> > Pardon me but could anyone enlighten me if python2.2 has a math function
> > to call to do factorials of integers?If not then is there a code snippet
> > for doing such a thing available?I tried to write some code for this
> > myself but with little success.
> > Thanks
> > Lol
>
> Hi,
>
> The other replies give a much more readable way of getting the factorial,
> but if you're looking for the ultimate in speed then...
>
> def fac(n):
>     return reduce(long.__mul__, range(1,n+1), 1L)
>
> ..would probably be a bit quicker. I'm not sure how much quicker though.
>
> Anyway, hope this is of some use,
> Regards,
> Andrew Wilkinson






More information about the Python-list mailing list