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

Hi, I'd like feedback to my code for assignment #1. Just want to hear from some people with more experience than me. I'll attach the files in a comment, thanks.

OpenStudy (anonymous):

OpenStudy (anonymous):

Looks all right. Only thing I can really suggest is a little optimization tweak. while divisor < a: # We can stop at the sqrt of a, since we're looking at factors.

OpenStudy (anonymous):

Thanks for the tip, stopping at the sqrt of a sped up the program quite a bit.

OpenStudy (anonymous):

Your table starts at rank 2 prime number value 3 it is missing rank 1 prime number value 2.

OpenStudy (anonymous):

From how I read the assignment, it sounded like it was asking to generate only the odd prime numbers (which only excludes 2). In the assignment, it says, "In formulating this condition, don’t forget that your program did not generate the first prime (2)." So that's why I purposely skipped "rank 1, prime number value 2."

OpenStudy (anonymous):

You're right, I should have looked at the hints before doing the assignment.

OpenStudy (anonymous):

The improvement that VirPriscus suggests really makes the code more efficient. I added a variable to count the number of modulos comparisons. With the sqrt added to my code there were 40579 comparisons, without it, there were 1853335, 45x more.

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!