why 'lambda' and 'reduce'?

Manuel Garcia news at manuelmgarcia.com
Thu Jun 12 18:15:55 EDT 2003


On Thu, 12 Jun 2003 22:36:52 +0200, Irmen de Jong
<irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote:

>Anyway it ran quite fast indeed... somehow I don't expect
>this kind of unreadable and horribly nested code to run
>fast too. Never mind. :-)

Thank heavens it doesn't take as much time to run as it did to write!

Actually 10000 digits wouldn't be much longer.  I am using a quadratic
iteration, so the number of valid digits is doubled with each step!
(It is amazing to me there are algorithms that can do this).  There
are other iterations that increase the number of valid digits times 3,
times 4, times 5, but they cannot be as cleanly implemented.

http://numbers.computation.free.fr/Constants/Pi/iterativePi.html

The '13' in the progam is the number of iterations needed for 5000
valid digits.  10000 digits would require 14 iterations, etc.

As horrible as it looks, after I added the last 'lambda', it runs just
as fast as a straightforward implementation.  The only inefficient
part is using '+' to concatenate strings, and I do that just to make
the string processing a little harder to spot.

Manuel




More information about the Python-list mailing list