elz (
elz) wrote in
intro_to_cs2009-11-11 10:52 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
Entry tags:
Poll & solutions
First:
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
#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.