what? (late nite entertainment) (*)
What is this? Another version of the well known ... def what(n): x,y = range(n), [0]*n x[1]= 0 z = 0 while z*z <= n: z+=1 if x[z]: x[z*z:n:z]=y[z*z:n:z] return [z for z in x if z] Regards, Gregor (*) at least in good old Europe
Well, it seems to generate primes less than n, but breaks if n < 2 (perhaps it should return an empty list?) Another entry for obfuscated python... %-) --Dethe On 28-Jan-04, at 2:33 PM, Gregor Lingl wrote:
def what(n): x,y = range(n), [0]*n x[1]= 0 z = 0 while z*z <= n: z+=1 if x[z]: x[z*z:n:z]=y[z*z:n:z] return [z for z in x if z]
This past week, everyday when I opened my Wall Street Journal, I was met with a full page ad from Microsoft. This ad was dominated by three simple words "Protect your PC." This strikes me as something akin to the Saudi government running ads in the New York Times in mid-September of 2001 saying "Protect your Tall Buildings." --Russ McGuire
More correctly, it generates a list of numbers less than n, then removes all numbers from that list that aren't prime. Also, it breaks if n < 3. Its definately an interesting implementation. I'm not sure I like the 'y' variable. Stephen. Dethe Elza wrote:
Well, it seems to generate primes less than n, but breaks if n < 2 (perhaps it should return an empty list?)
Another entry for obfuscated python... %-)
--Dethe
On 28-Jan-04, at 2:33 PM, Gregor Lingl wrote:
def what(n): x,y = range(n), [0]*n x[1]= 0 z = 0 while z*z <= n: z+=1 if x[z]: x[z*z:n:z]=y[z*z:n:z] return [z for z in x if z]
This past week, everyday when I opened my Wall Street Journal, I was met with a full page ad from Microsoft. This ad was dominated by three simple words "Protect your PC." This strikes me as something akin to the Saudi government running ads in the New York Times in mid-September of 2001 saying "Protect your Tall Buildings." --Russ McGuire
------------------------------------------------------------------------
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
On Wednesday 28 January 2004 11:22 pm, Stephen Thorne wrote:
More correctly, it generates a list of numbers less than n, then removes all numbers from that list that aren't prime. Also, it breaks if n < 3.
It also breaks with Python <= 2.2. Try this instead if you are so encumbered, like me: def what(n): x,y = range(n), [0]*n x[1]= 0 z = 0 while z*z <= n: z+=1 if x[z]: for i in range(z*z, n, z): x[i]=y[i] return [z for z in x if z] -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
participants (4)
-
Dethe Elza
-
Gregor Lingl
-
Stephen Thorne
-
Terry Hancock