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

here's my solution to problem set 1b, did I do this right? for l in range(0,b-1): d+=log(primeNums[l]) #Sum of the logs of all the primes to "n" print d print b #"n" e=b/d #ratio of sum of logs less than n, to n print e

OpenStudy (anonymous):

from math import * # headers of my program primeNums=[2,] x=3 d=0 print'Computing Primes using while loop' b=int(raw_input('Which prime Number would you seek today?'))

OpenStudy (anonymous):

its been a while since I've done algebraic problem solving, thirty years, actually so I am unsure of the direction of the "ratio" would I divide the sum of the logs of n by n? or would I divide n by the sum of the logs?

OpenStudy (anonymous):

I'm sorry, which course is this for? Without some idea of the problem set or instructions, it's impossible to tell if your solution works as intended.

OpenStudy (anonymous):

6.00 Intro to Computer Science(OCW). Problem set 1b. 1a was to return the thousandths prime number, 1b... Write a program that computes the sum of the logarithms of all the primes from 2 to some number n, and print out the sum of the logs of the primes, the number n, and the ratio of these two quantities. Test this for different values of n. I simply modified my 1a program after adding an input for varying integer choices, rather than modifying the script for each test value.

OpenStudy (anonymous):

from math import * primeNums=[2,] x=3 d=0 print'Computing Primes using while loop' b=int(raw_input('Which prime Number would you seek today?')) print'Computing Prime' while len(primeNums)<=b-1: #len(primeNums)<=999 #determines how high to 'find' primeNums for y in range (2,x): #returns number for prime divisor test z=x%y #tests for prime if z==0: #breaks from loop if not prime x+=1 #increments to next number break else: primeNums+=[x,] x+=1 # if num is prime, adds to list, and moves to next #print primeNums[b-1] #test to view all nums cantenated. print'Prime Number',b,'is: ',x-1 #prints thousandth prime num for l in range(0,b-1): d+=log(primeNums[l]) #Sum of the logs of all the primes to "n" print d,'Sum of the logs' print b, 'n' #"n" e=b/d #ratio of sum of logs less than n, to n print e, 'Ratio of the sum of the logs less than n, to n'

OpenStudy (anonymous):

if I take the ratio of the n, to the sum of the logs of primes to n, I come up with a number that encroaches zero the higher the prime. HOWEVER if I take the reverse, and take the ratio of the log of the sum of the logs of primes up to n, to n, then I come up with a number that is larger and larger as I go higher and higher. According to the wiki on "ratio" a ratio can be defined as: the relationship of an item that is portioned within another item to the whole of items. which would indicate I have my divisor backwards, as in my recipe I am returning the quotient of the'log of n'/'the sum of the logs of the primes up to n.' Which ironicaly returns a number that is closer to 0,instead of 1, the higher the prime I seek. so am I doing something wrong? or did I just prove the theory incorrect? the reverse quotient(ratio) returns higher numbers as I go higher.

OpenStudy (anonymous):

my program returns the result of "n is to sum, as 1 is to ??.

OpenStudy (anonymous):

discovered, problem, I was seeking ratio of my target input to sum of logs, instead of the sum of logs to the actual prime number. now my formula returns 1.0148 at 100th prime and 1.009 at 200th prime.

OpenStudy (anonymous):

I changed thus: n=x-2 for l in range(0,b-1): d+=log(primeNums[l]) #Sum of the logs of all the primes to "n" print d,'Sum of the logs' print b, 'n' #"n" e=n/d #ratio of sum of logs less than n, to n

OpenStudy (anonymous):

semantic error?

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!