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-16 09:10 am (UTC)
tassosss: Shen Wei Zhao Yunlan Era (Default)
From: [personal profile] tassosss
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 Date: 2009-11-16 09:15 am (UTC)

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. 13th, 2025 10:41 am
Powered by Dreamwidth Studios