kpmoore


Joined 1 year 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
#code to calculate possible McNugget combinations up to n = 55 nuggets

n=0
a=0
b=0
c=0
while n < 55:
    if 6*a + 9*b + 20*c < n:
        a = a + 1
    elif 6*a + 9*b + 20*c > n:
        a = 0
        b = b + 1
        if 9*b > n:
            b = 0
            c = c + 1
            if 20*c > n:
                c = 0
                n = n + 1 
    elif 6*a + 9*b + 20*c == n:        
        print 'For', n, 'McNuggets, a =', a, ', b =', b, ', c =', c
        a = a + 1

#code to calculate the largest quantity of McNuggets which cannot be obtained using the three sizes small, medium, and large

bestSoFar = 0     # variable that keeps track of largest number
                  # of McNuggets that cannot be bought in exact quantity
packages = (6,9,20)   # variable that contains package sizes
(small, medium, large) = packages
for n in range(1, 200):   # only search for solutions up to size 200
    a = 0
    b = 0
    c = 0
    while large*c < n:
        if small*a + medium*b + large*c < n:
            a = a + 1
        elif small*a + medium*b + large*c > n:
            a = 0
            b = b + 1
            if medium*b > n:
                b = 0
                c = c + 1
        if small*a + medium*b + large*c == n:
            break
        elif large*c > n:
            print n, "McNuggets cannot be bought in exact quantity."
            bestSoFar = n
print "Largest number of McNuggets that cannot be bought in exact quantity:", bestSoFar
 

kpmoore 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
#Problem 1

primes = 0
x = 2
y = 2
while primes < 1000 and y <= x:
    if x%y == 0 and x != y: #Then NOT Prime
        y = 2
        x = x + 1
    elif x == y: #Then PRIME
        print x
        primes = primes + 1
        y = 2
        x = x + 1        
    else: #Continue Testing
        y = y + 1

# Problem 2

from math import *

primes = 0
x = 2
y = 2
sum = 0
while primes <= 1000 and y <= x:
    if x%y == 0 and x != y: #Then NOT Prime
        y = 2
        x = x + 1
    elif x == y: #Then PRIME
        n = x
        y = 2
        x = x + 1
        primes = primes + 1
        if n <= 1000:
            sum = sum + log(n)
            n = n + 1
            print sum
    else: #Continue Testing
        y = y + 1

kpmoore 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1
last_name = raw_input('What is your last name? ')
first_name = raw_input('What is your first name? ')
print "Your name is", first_name, last_name

kpmoore 1 year ago