MIT OCW Homework 1

I’ve been working on the Introduction to Computer Science from MIT’s OpenCourseWare.

Mashing through the homework is a double-struggle as I don’t really know Python but after about 2 hours I figured out the first problem of the first assignment:

# Problem Set 1
# Name: Ian Hall
# Collaborators: akonkol
# Time: too long
#
potential_primes = range(1,10000)
howmanyprimes = 0
for p in potential_primes:
dividesby = 0
divisors = range(1,p)
for d in divisors:
if p%d == 0 and p != d and d != 1:
dividesby = dividesby + 1
if dividesby == 0 and p != 1 and howmanyprimes < 1000:
howmanyprimes = howmanyprimes + 1
print(p,'is prime and',howmanyprimes,'of 1000 primes found.')

I’m pretty excited to get it working because it’s my first Python program, I’m not “MIT smart,” and I am not terribly adept at math.

what we risk will be regained

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s