elz: (emerson)
elz ([personal profile] elz) wrote in [community profile] intro_to_cs 2009-11-12 01:31 am (UTC)

Trying to break it down can help a lot: how would you check to see if a particular number (something small, maybe 5 or 6) was prime or not? If you write out the steps, just in plain English, that can be a roadmap for what you have to translate into code. Once you know how to check to see if a particular number is prime, you'd want to figure out how to generalize the steps so you can check to see if any given number is prime. To figure out the nth prime number, you just need a way to keep track of the ones you already know and count the length of the list.

And this:

You might think about which integers you need to check as divisors – certainly you don’t need to go beyond the candidate you are checking, but how much sooner can you stop checking?

is a hint that saves a lot of work. If you want to know if 5 is prime, do you need to divide it by 4? If not, why not?

(And I'd say definitely worry about one at a time!)

Post a comment in response:

This community only allows commenting by members. You may comment here if you're a member of intro_to_cs.
(will be screened if not on Access List)
(will be screened if not on Access List)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting