mattb


Joined 9 months ago
Homeworks submitted:
Homework comments:
3
0

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 17% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 3, HW 1

PS2

#Problem Set 2 (Part I)
#Name: mattb
#Time: 00:10
#Collaborators: Curious Reef

for n in range (50,55):
    for a in range (0, n/6 + 1):
        for b in range (0, n/9 + 1):
            for c in range (0,n/20 + 1):
                if (6 * a) + (9 * b) + (20 * c) == n:
                    print a,'a', ' + ',b,'b', '+', c,'c = ', n

# Problem Set 2 (Part II)
# Name: mattb
# Collaborators: Curious Reef
# Time: 5 minutes

#All values greater than x + 5 can be attained
#by adding multiples of 6 to the appropriate value in
#the range x, x + 1,... x + 5

# Problem Set 2 (Part III)
# Name: mattb
# Collaborators: Curious Reef
# Time: 2:00

maxn = 6
ncount = 0
n = 7
while ncount < 6:
    n += 1
    ans = False
    for a in range(0,n/6 + 1):
        for b in range(0,n/9 + 1):
            for c in range(0,n/20 + 1):
                if (6*a)+(9*b)+(20*c) == n:
                    ans = True
    if ans:
        ncount += 1
    else:
        ncount = 0
        maxn = n
        print maxn                   
print 'Largest number of McNuggets that \
cannot be bought in exact quantity: ',  maxn

# Problem Set 2 (Part IIII)
# Name: mattb
# Collaborators: Curious Reef
# Time: 20 mins

x = int(raw_input('x = '))
y = int(raw_input('y = '))
z = int(raw_input('z = '))

packages = (x,y,z)

maxn = 0
ncount = 0
n = 0
while ncount < 6 and n <200:
    n += 1
    ans = False
    for a in range(0,n/packages[0] + 1):
        for b in range(0,n/packages [1] + 1):
            for c in range(0,n/packages [2] + 1):
                if (x*a)+(y*b)+(z*c) == n:
                    ans = True
    if ans:
        ncount += 1
    else:
        ncount = 0
        maxn = n
        print maxn                   
print 'Given package sizes ', packages,' the largest \
number of McNuggets that cannot be bought in exact quantity is: ',  maxn



mattb 9 months ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1

PS1 - any suggestions/comments would be appreciated.

# Problem Set 1a
# Name: mattb
# Collaborators: Curious Reef
# 2 days

count = 1
candidate = 3

while count < 1000:
    divisor = candidate/2
    while divisor > 1:
        if candidate % divisor == 0:
            candidate += 2
            divisor = candidate / 2
        else:
            divisor -= 1
    count += 1
    if count < 1000:
        print count, ' : ', candidate
        candidate += 2
        
print 'The 1000th prime is:', candidate




# Problem Set 1b
# Name: mattb
# Collaborators: Curious Reef
# Time: 6 hours

import math

candidate = 3
n = int(raw_input('n = '))
logsum = math.log(2)

while candidate < n - 1:
    divisor = candidate/2
    while divisor > 1:
        if candidate % divisor == 0:
            candidate += 2
            divisor = candidate / 2
        else: divisor -= 1
    lastprime = candidate
    logsum += math.log(candidate)
    candidate += 2
    
print 'n = ', n
print 'Sum of logs = ', logsum
print 'Ratio = ', (logsum/(n))

mattb 9 months ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1

ps0

# Problem Set: 0
# Name: Mattb
# Collaborators: Curious Reef
# Time: 1
#
lastname = str(raw_input('Enter your last name: ')) #Ask user to enter last name
firstname = str (raw_input('Enter your first name: ')) #Ask user to enter first name
print firstname,lastname

mattb 9 months ago