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 06:47 am (UTC)from math import * def primes_upto_n(n): primes = [2] choice = 1 while len(primes) < n: choice += 2 rt = sqrt(choice) isPrime = True # since we need all primes from 2 to n, this optimization works # we can prime-factor all non-prime numbers. for i in range(0, len(primes)): poss = primes[i] if (choice % poss) == 0: isPrime = False break if (poss >= rt): break if isPrime: primes.append(choice) return primes primes = primes_upto_n(1000) nthPrime = primes[-1] sums = reduce(lambda sum,prime: sum+log(prime),primes) print "Sum: ", sums print "Nth Prime: ", nthPrime print "sums / Nth Prime: ", sums/nthPrimeYeah, this includes some weird-crazy optimizations >_<
kUsOwOPPqqovUv
Date: 2012-05-03 09:49 am (UTC)