elz: (ada-tubes)
elz ([personal profile] elz) wrote in [community profile] intro_to_cs2009-11-11 10:52 pm
Entry tags:

Poll & solutions

First:

Open to: Registered Users, detailed results viewable to: All, participants: 25


Tickyboxes!

View Answers

Finished lecture 2
24 (96.0%)

Finished problem set 1
15 (60.0%)



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!
ungemmed: (Default)

[personal profile] ungemmed 2009-11-12 05:52 am (UTC)(link)
argh, Dreamwidth keeps on choking on my solution for problem 2! I guess it's reading the code as some malicious hacking attempt or something.
badgerbag: (Default)

[personal profile] badgerbag 2009-11-12 06:18 am (UTC)(link)
try wrapping it in
  or  tags maybe...
ungemmed: (Default)

[personal profile] ungemmed 2009-11-12 06:24 am (UTC)(link)
Thanks! It actually turned out, though, that NoScript was being overzealous and thought Dreamwidth was trying to hack me. o.O
ungemmed: (Default)

[personal profile] ungemmed 2009-11-12 06:25 am (UTC)(link)
Problem 2
import math

n = int(raw_input('n? '))

primes = [2]
x = 3
logs = 0
while x <= n:
    divisible = False
    root = math.sqrt(x)
    for y in primes:
        if x % y == 0:
            divisible = True
            break
        if y > root:
            break
    if not divisible:
        logs += math.log(x)
        primes.append(x)
    x += 2
print logs
print logs / n