
David W. answered 06/23/16
Tutor
4.7
(90)
Experienced Prof
Hi,
One of my favorite easy computer programming assignments is to find the prime numbers from 1 to 1000 as a spiral process:
- determine whether one given number (say, 17) is prime by dividing it by smaller numbers starting at 2
When that works:
- do the above for all numbers from 2 to 20
When that works:
- do that for all numbers from 2 to 1000 (note: computers are very fast)
When that works:
- if you want improvements, stop after dividing by N/2
When that works, more improvements:
- only divide N by the primes already found (means saving them in an array)
. . .
This can go on and on (but never, never waste time with errors).
I made a 30-minute audio with flow chart slides of this process if you are interested.
In preparation, we read the Wikipedia article on the Sieve of Eratosthenes and watch the animation. Then, we read what we can of the Wikipedia article on the RSA Problem [this provides great motivation].
Now, in my lifetime, computer processors have dramatically increased in speed and computer storage has increased tremendously -- all at a much lower cost. So, I have done additional work on efficient algorithms and data structures for determining prime numbers.
I would be interested in your algorithm. I could determine whether it works using a computer. Send me a message if you are interested in my comments.
p.s., 30 is well-chosen because it is 2*3*5 (first primes)