Shortest prime number program

Ralf Muschall ralf at tecont.de
Sat Feb 11 17:11:00 EST 2006


Christoph Zwerschke wrote:
> dickinsm at gmail.com schrieb:
>> How about:

>> [2]+[x for x in range(1,99) if 2**x%x==2]

> If the range goes beyond 340, it also gives non-primes...

[2,3]+[x for x in range(1,99) if 2**x%x==2 and 3**x%x==3]
[2,3,5]+[x for x in range(1,99) if 2**x%x==2 and 3**x%x==3 and 5**x%x==5]

SCNR, Ralf

PS: They both break at 561, and further strengthening of the
condition will not help.  Manual loop unrolling as follows works:

[2,3,... <insert all primes here>]+[x for x in range(1,99) if False]

For sufficiently small values of 99, this will also be a rather
short program.



More information about the Python-list mailing list