Revizia anterioară Revizia următoare
Problem: prime number generator
A while back Ovidiu Gheorgheoiu told me this neat problem:
How would you build an efficient prime number generator.
Let the generator be an object G with the method nextPrime(). When we call it G.getNextPrime() the first time it returns 2. Every time we call it again it returns the next prime number.
So if we do:
G = PrimeGenerator()
print G.nextPrime()
print G.nextPrime()
print G.nextPrime()
We'll get
2
3
5