Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 25 Online
OpenStudy (anonymous):

Ok. I am going to post my code for problem set 1a. It works fine now, I would just like to see if there was an easier way to do it and if there is anything I could do to improve my existing code. Thanks in advance! http://dpaste.com/hold/1549898/

OpenStudy (e.mccormick):

For one thing, you only need to test odd numbers. This is because after 2 there are no even primes. It looks like you are only testing the numbers by dividing by things up to the first half. This is good because it tests less and is faster. I used to have some that other people had did, but I recently changed machines and I think that file was not in one of the folders I transferred. =/

OpenStudy (anonymous):

True, I never thought of testing only odd numbers. That would be very easy to fix. Thanks for the feedback!

OpenStudy (e.mccormick):

Sometimes it is that principal of doing the simplest, smallest, part that can make a difference in code. For finding the 1000th prime, not much difference. But for say the 1,000,000,000th prime... well, you can cut out half the work by incrementing over all the evens. Thinking about those sorts of details is something you develop as you learn.

OpenStudy (anonymous):

I hope so. I think I was more concerned with making it work than making it efficient. That is definitely something I will have to work on. I'm glad you pointed it out so that I will be aware in the future.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!