[Edu-sig] Kirby Urner's Sieve of Eratosthenes
Dustin James Mitchell
djmitche@midway.uchicago.edu
Thu, 8 Jun 2000 14:33:06 -0500 (CDT)
On Mon, 5 Jun 2000, Kirby Urner wrote:
> PS: Dustin, would your agree that reduce(mul,terms) and
> reduce(add,terms) are a useful way to introduce sums and
> products, corresponding to geeky greek symbols capital
> SIGMA and capital PI. In other words:
>
> from operator import mul,add
>
> def sum(terms):
> """Same as SIGMA (terms is a list)"""
> return reduce(add,terms)
>
> def product(terms):
> """Same as PI (terms is a list)"""
> return reduce(mul,terms)
>
> Would these be useful as "math through programming"
> Python definitions?
>
> Note: n! would be the same as product( range(1,n+1) ).
I like this, and it's extremely compact, but I would start by simply using
sum() and product() as black-box operators, and only delving into their
implementation a little bit later (but still before using filters).
Dustin
---------------------------------------------------------------------
| Dustin Mitchell )O( |
---------------------------------------------------------------------