Shortest prime number program
Mitja Trampus
nun at example.com
Sat Feb 11 06:35:41 EST 2006
swisscheese wrote:
> I figured someone out there must have written a minimal code size prime
> number generator. I did not find one after a bit of searching around.
> For primes up to 100 the best I could do was 70 characters (including
> spaces):
>
> r=range(2,99)
> m=[x*y for x in r for y in r]
> [x for x in r if not x in m]
A more straightforward and somewhat shorter solution:
r=range(2,99)
[x for x in r if [x%d for d in r].count(0)<2]
I'm sure it can be made shorter still.
More information about the Python-list
mailing list