elz: (ada-tubes)
[personal profile] elz posting in [community profile] intro_to_cs
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!

Date: 2009-11-12 05:48 am (UTC)
ungemmed: (Default)
From: [personal profile] ungemmed
Here are mine! They're a lot like [personal profile] elz's, but I'm only checking factors up to the square root. (Since all factors above the square root are "balanced" by factors below it, if I haven't encountered any factors by the time I get to the square root I'm not going to encounter any.)

Problem 1

import math

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

Date: 2009-11-12 05:52 am (UTC)
ungemmed: (Default)
From: [personal profile] ungemmed
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.

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

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

Date: 2009-11-12 06:25 am (UTC)
ungemmed: (Default)
From: [personal profile] ungemmed
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

WzOvEpgUHNwG

Date: 2012-05-03 02:40 pm (UTC)
From: (Anonymous)
Well, I actually know two pforos: one leads to a very quick solution but requires the knowledge of some number theory. The other proof works on first principles but leads to a much longer computation. I was assuming most readers would find the second one.

Profile

Introduction to Computer Science

July 2010

S M T W T F S
    123
45678910
11121314151617
18192021222324
2526272829 3031

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 12th, 2025 03:11 pm
Powered by Dreamwidth Studios