
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
S Connor wrote:I'm just thinking there needs to be a way to record which numbers are not prime.
I agree. Here's the better link: Salvin.in
I agree. Here's the better link: Salvin.in
Piet Souris wrote:..Now, does that look like the Sieve being the goal of this assignment? I have my doubts...
I agree. Here's the better link: Salvin.in
S Connor wrote:Thanks for the advice. I am following an exercise book which ...
S Connor wrote:I'm wondering if there is an elegant solution that does not require recording of which numbers are prime?
I agree. Here's the better link: Salvin.in
S Connor wrote:'How many numbers up to 10,000 do you have to test to ensure that you have found all the primes?'
Well it seems to me that you have to test all the numbers up to 9973 to ensure that you have found them all. But how would you translate this into code?
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
S Connor wrote:Here is my solution to the first part of the problem...
I agree. Here's the better link: Salvin.in
Junilu Lacar wrote:
S Connor wrote:'How many numbers up to 10,000 do you have to test to ensure that you have found all the primes?'
Well it seems to me that you have to test all the numbers up to 9973 to ensure that you have found them all. But how would you translate this into code?
Again, this seems to hint at the Sieve of Eratosthenes...
But I think you should answer the question with √n − 1 because 1 doesn't count as a prime number.Paul Clapham wrote: . . . If you use the Sieve of Eratosthenes then you don't need to test any numbers to see if they are prime. . . . There's basically no testing of any kind going on.
Paul Clapham wrote:The question is unclear, though.
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
S Connor wrote:
a)Write a method that determines whether a number is prime. (I can do this part.)
b)Use this method in an application that determines and displays all the prime numbers less than 10,000. How many numbers up to 10,000 do you have to test to ensure that you have found all the primes?
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
S Connor wrote:
Steve Fahlbusch wrote:Carey,
You are correct, but what i was trying to throw out there was once you got to sqrt 10000 you had done all of the checking you need to do globally.
Also, the outer loop only need to to iterate to 6n+1 > 10000.
and like you said, the inner loop (inside the isPrime function) only needs to iterate to sqrt n.
thanks for the clarification.
steve
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]
All of the world's problems can be solved in a garden  Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDBOpenSourceNoSQLDatabase
