why 'lambda' and 'reduce'?
news at manuelmgarcia.com
Fri Jun 13 00:15:55 CEST 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.
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.
More information about the Python-list