Poll & solutions
Nov. 11th, 2009 10:52 pmFirst:
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-12 04:36 am (UTC)#!/usr/bin/env python # ps1a.py # MIT problem set 1a, by me # start with some helpful variabubbles # note that we're starting with the first prime preloaded; this is admittedly kludgetastic counter = 0 number = 2 while counter < 1000: for i in range(2,number): if number % i == 0: break # if there were no factors, print the prime and count it else: counter +=1 print counter, ": ", number, 'is prime' number += 1And for problem 2:
#!/usr/bin/env python # ps1b.py # MIT problem set 1b, by me from math import * max = input("enter a number: ") sum = 0 number = 2 # we're going to work through a whole range of numbers... while number <= max: # test each to see if it's prime for j in range(2,number): if number % j == 0: break else: print number, "is prime: " sum += log(number) number +=1 # spit stuff out print "sum of logs: ", sum print "n = ", max print "ratio: ", sum/max