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!

Problem 1a

Date: 2009-11-15 10:30 pm (UTC)
quartzpebble: (Default)
From: [personal profile] quartzpebble
I started with 3 so that I could only check odd numbers, though using a list like some others did might have been more elegant. I also only checked factors up to the square root.


from math import *

target_primes = 1000 #nth prime that we want to compute
current_no = 3
prime_counter = 2
i = 3

while prime_counter < target_primes:
prime_counter += 1
current_no += 2
i = 3

while i <= sqrt(current_no):
if current_no%i == 0:
current_no += 2
i = 3

else:
i += 2
print str(current_no) + " is the " + str(prime_counter) + "th prime."


(Now with better formatting here.)

Not actually better formatting

Date: 2009-11-15 10:32 pm (UTC)
quartzpebble: (Default)
From: [personal profile] quartzpebble
Is there a way to keep the indents in my code, or do I need to replace tabs with spaces here? It looked fine before I posted. :P

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:07 pm
Powered by Dreamwidth Studios