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

Can someone give the solutions for Problem Set 1?

OpenStudy (naga447):

What is problem set 1?

OpenStudy (anonymous):

Kevin Ladenheim posted his solution on the web at: http://www.kevinladenheim.com/2011/07/mit-600-problem-set-1-problem-1.html my solution is: # inintialize the variables n = 1 # the iterator that will be used to check each odd # number greater than 2 cpr = 1 # (c)urrent (p)rime (r)ank Lop = 3 # (L)ist (o)f (p)rimes starts with the first prime cond = 'possible prime' # test condition import time while cpr < 100000: for primes in range(2,Lop): # primes are calculated below and appended to this # list. The primes are then used in the following # block of code. ts = 2 * n + 1 # test subject to be evaluated if cond == 'possible prime' and primes <= ts ** 0.5: # for the ith prime in the list of primes this # block is evaluated iff all lesser primes are # not primes if ts % primes == 0: cond = 'not prime' # if a factor is found # this could have been any # value break # reduces run time by breaking the # for loop when the first factor is found else: cond = 'possible prime' if cond == 'possible prime' : # if all primes less than root(test Subject) are not # factors than test subject is a prime and is # appended to the list of primes Lop = int (ts ** 0.5) + 2 cpr = cpr + 1 # cpr is increased if ts is a prime # print progress through the evaluation #print 'The ', cpr, ' prime is ', ts cond = 'possible prime' # reset the test condition for # the next test subject n = n + 1 # increase the test subject iterator print 'Finished' print 'The ', cpr, 'th prime is ', ts

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!