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 04:36 am (UTC)
gchick: Small furry animal wearing a tin-foil hat (Default)
From: [personal profile] gchick
Interesting how completely different mine is from elz's, even for a program this small:

#!/usr/bin/env python
# ps1a.py 
# MIT problem set 1a, by me

# start with some helpful variabubbles
# note that we're starting with the first prime preloaded; this is admittedly kludgetastic

counter = 0
number = 2

while counter < 1000:

	for i in range(2,number): 
		if number % i == 0:      
			break 
				
        # if there were no factors, print the prime and count it
	else:
		counter +=1
		print counter, ": ", number, 'is prime'
			
	number += 1



And for problem 2:

#!/usr/bin/env python
# ps1b.py 
# MIT problem set 1b, by me

from math import *

max = input("enter a number: ")
sum = 0
number = 2

# we're going to work through a whole range of numbers...
while number <= max:

	# test each to see if it's prime
	for j in range(2,number):
		if number % j == 0:      
			break
	else:
		print number, "is prime: "
		sum += log(number)
	number +=1
	
# spit stuff out	
	
print "sum of logs: ", sum
print "n = ", max
print "ratio: ", sum/max		
	
Edited Date: 2009-11-12 04:38 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. 12th, 2025 03:07 pm
Powered by Dreamwidth Studios