Poll & solutions
Nov. 11th, 2009 10:52 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
First:
Also, it occurs to me that it might be handy to have a place to post/discuss solutions to the problem sets, to see what we can learn from each other in the absence of TAs. If you actually go to MIT and the problem sets are still the same, don't read these. ;)
Fire away!
Open to: Registered Users, detailed results viewable to: All, participants: 25
Tickyboxes!
Also, it occurs to me that it might be handy to have a place to post/discuss solutions to the problem sets, to see what we can learn from each other in the absence of TAs. If you actually go to MIT and the problem sets are still the same, don't read these. ;)
Fire away!
no subject
Date: 2009-11-19 05:47 am (UTC)My solutions also seem a little clunky, but I guess they work...
My solution for problem 1:
count = 2
numb = 3
n = int(raw_input("What prime are you trying to find?"))
while(count<=n):
i = 2
isprime = 1
half = numb/2
while(isprime > 0 and i < half):
if numb%i != 0:
i = i+1
else:
isprime = isprime-1
if isprime == 1:
if count < n:
count = count + 1
numb = numb + 2
else: break
else:
if count <= n:
numb = numb + 2
print numb,"is prime number",count
My solution for problem 2:
from math import *
n = int(raw_input("What number?"))
logprimes = [log(2)]
numb = 3
while(numb<=n):
i = 2
isprime = 1
root = sqrt(numb)
while(isprime>0 and i<=root):
if numb%i != 0:
i = i+1
else:
isprime = isprime-1
if isprime == 1:
logprimes.append(log(numb))
if numb < n:
numb = numb + 2
else: break
else:
if numb <= n:
numb = numb + 2
print "The sum of the logs is",sum(logprimes)
print "The number is",n
print "The ratio of the sum and n is",sum(logprimes)/n