View Single Post
Old 2017-04-20, 16:01   #7
bgbeuning
 
Dec 2014

3·5·17 Posts
Default Suggestion

If both objects start at the same value and both go up, then nextPrime() generates
the same values and they do not need two objects.

How about this? It is a mathematically nonsense problem but a programming problem.

If they extend their class to have a prevPrime() method, then ask them to
"make two objects, one generating primes going up from 1, the other generating
primes down from 1,000,000 and find the largest sum of the two primes"

Primer low(1);
Primer high(1000000);

while( true ) {
int l = low.nextPrime();
int h = high.prevPrime();
if( l > h ) break; // done
int sum = l + h;
if( sum > ...
}
bgbeuning is offline   Reply With Quote