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

Solution to p1b, if someone could check this :)

OpenStudy (anonymous):

Found an error, will post another solution soon :)

OpenStudy (anonymous):

Here it is. I think it is ok, the number (ratio) approaches 1 as the number of primes is increased (for example, for 100 primes it's .933, for 500 primes it's .979, for 2k primes it's .99,

OpenStudy (anonymous):

I get a slighty smaller logsum number, I think because you are not supposed to add the last one, ie if I put 1000 it should add all up to 999. Therefore the ratio is a bit different too.

OpenStudy (anonymous):

Well according to the question , should not we ask for any random number rather than number of primes? : o. .please clarify..i have made my program on that basis ..please take a look and clarify my doubt.. thanks

OpenStudy (anonymous):

sunu0000, please post your code in dpaste.com it is simple and easy for everyone to use. I can't access your code on my computer. http://dpaste.com/

OpenStudy (anonymous):

or pastebin is fine too.

OpenStudy (anonymous):

http://dpaste.com/hold/563184/ here it is :)

OpenStudy (anonymous):

Yes, you should be able to enter a number n, and determine the ratio up to but not including the n itself. Haha your program is better than mine lol good pointing out. But you have included the n as well.

OpenStudy (anonymous):

nope :\ i haven't..take a close look...the n does not go into the list of primes..hence it does not go into the sum of logs either :p hope u can understand my english...it actually sucks...i was looking for a spoken english course or something..could not find it though :(

OpenStudy (anonymous):

I think you'll find it does count it. http://dpaste.com/563220/

OpenStudy (anonymous):

well try putting the input as 3 i.e n=3 and u will find out that it does not actually count log(3) the only thing it counts is log(2).. the code counts log(n) only for n=2 ..because i have initialized prime_number to (2,)...so it always contains 2..:(

OpenStudy (anonymous):

How odd. You are right, when I put a low number in, it does not count the n in the prime list, but if you put a high number in, it does. I initally tried 7919. Any number higher than 43 will add the n in the list. I can't see why though.

OpenStudy (anonymous):

Not true, either. 11 puts the 11 in the prime list too.

OpenStudy (anonymous):

I found the issue with this. When the iteration before proves to be not a prime, it does go back to the first test. So... 7 won't be in the list because 5 is a prime. But 11 adds itself to the list because 9 isn't, and it skips the first test. Same again if you look at 13 will not add, but 17 will add itself.

OpenStudy (anonymous):

Well then i have to re-analyze and fix it... Thanks for your analysis :D

OpenStudy (anonymous):

Ah, debugging... half the fun of programming... Irritating when you think you are done though...

OpenStudy (anonymous):

just got it...:) check this out... http://dpaste.com/hold/563578/

OpenStudy (anonymous):

now nothing can put than n in my prime list :D...SPECIAL SECURITY TO KEEP N OUT :P

OpenStudy (anonymous):

:) Fixed. It works perfect as far as I can see.

OpenStudy (anonymous):

lol I like the idea of a 'door feather' statement... that should be offical programming talk...

OpenStudy (anonymous):

lol...btw i meant that n :p and..whats the hold at dpaste for?

OpenStudy (anonymous):

I've never used it but it makes it stay up for longer. The code gets deleted after a week.

OpenStudy (anonymous):

could u plz suggest how to break out successfully of my Mcnuggles code? it's there in another question :}

OpenStudy (anonymous):

I wrote what I thought in that post now.

OpenStudy (anonymous):

Folks, I wanted to take this problem just a step further and plot Primes = (2,3,5,7,9,...) vs logPrimes = (log2, log2+log3, log2 + log3 + log4, ...) to visualize the convergence. Has anyone tried to do this? Ideas?

OpenStudy (anonymous):

I'll try and share my solution...perhaps tonight..right now doing problem set 3 :)

OpenStudy (anonymous):

Done!!.. check this out http://dpaste.com/hold/564836/

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!