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!
tassosss: Shen Wei Zhao Yunlan Era (Default)

[personal profile] tassosss 2009-11-16 09:10 am (UTC)(link)
This is my solution to problem 1. It's not very elegant or complicated and I didn't do more than screen out even numbers for the factors.


#Initialization of terms
Number = 3 #lowest odd prime
primeCounter = 2 #inclusive of 2 and 3
Test = 3 #lowest possible factor for odd numbers

while(primeCounter < 1000):
while(Test < Number):
if Number%Test > 0: #checks to see if number is divisible by anything
Test = Test + 2 #if it is not then tries the next odd number
else: Test = Number + 1 #if it is divisible then it halts the loop
if Test == Number: #test can only reach the number if it is non divisible
primeCounter = primeCounter+1 #so the prime counter goes up
Number = Number + 2 #number goes to next odd number
Test = 3 #test is reset to lowest potential odd factor
print 'The', primeCounter,'th prime is' #final result is printed
Number = Number - 2
print Number

eta - I have no idea how to get the indents to show up.
Problem 2 tomorrow.
Edited 2009-11-16 09:15 (UTC)