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

Here is my code for Problem Set 1. Any ways to condense code? Part 1: http://dpaste.com/725513/ Part 2: http://dpaste.com/725516/ Both work fine. Ask away if you are stuck.

OpenStudy (anonymous):

congrats here is mine, i stored all the primes in a list and kept looking till there were 1000 items in the list - http://dpaste.com/725633/

OpenStudy (anonymous):

Wow, your script is so nice and concise, and it works too:o. Too bad I don't really understand what you did b/c i don't know much of the more complex syntax. Good job though, hopefully after i'm done this course I can go back and understand what you did haha.

OpenStudy (anonymous):

bwCA: nice solution. Attached is my version. I short circuited 2 and 3. Hope this helps.

OpenStudy (anonymous):

kevinw198: regarding my second solution I used log where you used log (,10). Our answers defer and I don't know which one is the correct. Maybe someone can throw in his/her answers into the mixture. My solution seems to agree with the ratio becoming 1 as the primes become larger. Hope this helps.

OpenStudy (anonymous):

kevinw198: If I remove the log(,10) and replace it with log -- I think this is natural log and change the lines (there are two) ratio=n/sum to ratio=x/sum we match.

OpenStudy (anonymous):

I don't know why I used based 10 instead of natural log. I assumed natural log was "ln" function, and in high school, log base 10 was usually just written as log for me. But I think the code is correct though. I looked at your solution, but I didn't really understand what the break function does.

OpenStudy (anonymous):

The break function serves to exit from within a loop and continue from the first line after. Imagine you have a for loop from 1 to 1000. In order "jump out" you use break. Hope this helps.

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!