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:31 am (UTC)from math import * def primes_up_to_n(upper_limit): n = 3 primes = [2] while n <= upper_limit: n_is_prime = True for prime in primes: n_is_prime = (n%prime != 0) if n_is_prime is False: break if n_is_prime: primes = primes + [n] n = n + 2 return primes def product_of_primes_to_n(n): primes = primes_up_to_n(n) sum_of_logs = 0 for prime in primes: sum_of_logs += log(prime) print "The sum of the logs of the primes, the number n, and the ratio of these two quantities are:" print "%f, %i, %f" % (sum_of_logs, n, sum_of_logs/n) n = int(raw_input('Give me an n:\n')) product_of_primes_to_n(n)It would be more efficient if I smushed them together, but I wanted to see if the first function would work. For, you know, all the times I need lists of prime numbers in my daily life. *g* I'm not totally sure why the ratio is significant, but it does get closer to 1.
LMsxQgfQKZIYxQHrT
Date: 2012-05-03 01:18 pm (UTC)