Code: Select all
def eratosthenes(n):
old = 0
sieve = [1] * 2 + [0] * (n - 1)
for i in range(int(n**0.5)):
if not sieve[i]:
for j in range(i*i, n+1, i):
sieve[j] = 1
if i != old:
old = i
print i, " ",
return sieve
eratosthenes(1000000)
I added a bit to print out the Prime numbers. But, where they actually prime numbers? Lets segway back to 1995-6...
Back then there was a Windows programming language called Delphi and it was all the rage. A few of us (hello Stephen) started the Busselton Delphi User Group (BDUG) and we would try and meet up monthly. One project I did was to write a simple Prime number program to help benchmark the early PC's:
In the above screenshot, I have opened up one of the menu items (RH window) that listed some of the previous historical benchmarks! On the LH side, I show the current speed to generate the list of Primes up to 37,000 on my 3.5yo (CPU: i5-2540M - 2.6GHz) laptop. It managed it in 0.172 seconds.
The obligatory About window:
Whoops, that email address won't work!
LOL - how times change
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Yes, comparing the two lists show that the above python code was generating Prime numbers, just very slowly! Also, for some reason, even with the large 10,000,000 number, it only spat out 3137 prime numbers and it took around 47.9 seconds (time varies a bit) to do so.
At least it's a LOT faster than my first computer: a 1979 TRS-80 Model 1, running at 1.7MHz. That was my first go at writing a Prime Number generator. I first wrote it in BASIC. I don't remember whether it was searching of 1000, or 10,000, but I manually drew a graph on paper listing various results, and I worked out it was going to take a bout a week to reach the goal I had set it. I think that might have set me off on my first foray into writing Z-80 assembly code. Yep, it was much faster and spat out the answer in a few hours. I was very impressed.
Footnote: So, what happened to the BDUG group you ask? It lasted for a few years and then morphed into a more exiting Linux user group which lasted until around 2003 when StephenE and myself coincidently both sold our respective businesses at the same time and moved onto other ventures. I think the Wayback Machine once had a copy of one of the 1998? Publisher based webpages I posted about the groups meetings.