Solution to p1b, if someone could check this :)
Found an error, will post another solution soon :)
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,
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.
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
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/
or pastebin is fine too.
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.
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 :(
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..:(
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.
Not true, either. 11 puts the 11 in the prime list too.
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.
Well then i have to re-analyze and fix it... Thanks for your analysis :D
Ah, debugging... half the fun of programming... Irritating when you think you are done though...
now nothing can put than n in my prime list :D...SPECIAL SECURITY TO KEEP N OUT :P
:) Fixed. It works perfect as far as I can see.
lol I like the idea of a 'door feather' statement... that should be offical programming talk...
lol...btw i meant that n :p and..whats the hold at dpaste for?
I've never used it but it makes it stay up for longer. The code gets deleted after a week.
could u plz suggest how to break out successfully of my Mcnuggles code? it's there in another question :}
I wrote what I thought in that post now.
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?
I'll try and share my solution...perhaps tonight..right now doing problem set 3 :)
Join our real-time social learning platform and learn together with your friends!