jbuck0


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

1. 6(2) + 9(2) + 20(1) = 12 + 18 + 20 = 50 McNuggets 6(1) + 9(5) + 20(0) = 6 + 45 + 0 = 51 McNuggets 6(2) + 9(0) + 20(2) = 12 + 0 + 40 = 52 McNuggets 6(1) + 9(2) + 20(1) = 6 + 18 + 20 = 53 McNuggets 6(0) + 9(6) + 20(0) = 0 + 54 + 0 = 54 McNuggets 6(1) + 9(1) + 20(2) = 6 + 9 + 40 = 55 McNuggets

50 + 6 = 56 McNuggets 51 + 6 = 57 McNuggets 52 + 6 = 58 McNuggets 53 + 6 = 59 McNuggets 54 + 6 = 60 McNuggets 55 + 6 = 61 McNuggets 50 + 6 + 6 = 62 McNuggets 51 + 6 + 6 = 63 McNuggets 52 + 6 + 6 = 64 McNuggets 53 + 6 + 6 = 65 McNuggets

  1. Given package sizes of 6, 9, and 20 and the possibility of buying between 'x' and 'x+5' McNuggets at once, we can assume that any number of McNuggets larger than 'x' can be bought because 'x+6' McNuggets would simply be the original 'x' amount of McNuggets plus an extra box of six. From that we can figure out that 'x+7' McNuggets would be 'x+1' McNuggets plus an extra box of six, and so forth.
# Problem Set 2

# pt. 3

n = 1
csols = 0
solution = 0
found = 0

while csols < 6 :

    found = 0

    for a in range (0, 9) :

        for b in range (0, 6) :

            for c in range (0, 3) :

                if (6 * a) + (9 * b) + (20 * c) == n :
                   found = 1

    if found == 1 :

        csols += 1

    else :

        csols = 0
        solution = n

    n += 1

print "Largest number of McNuggets that cannot be bought in exact quantity:", solution


# pt. 4

bestSoFar = 0
packages = (6,9,20)

for n in range(1, 200) :

    exact = False
    for a in range (0, 33) :

        for b in range (0, 22) :

            for c in range (0, 10) :

                if (packages[0] * a) + (packages[1] * b) + (packages[2] * c) == n :

                    exact = True
                    break

    if exact == False and bestSoFar < n :

        bestSoFar = n

print "Given package sizes " + str(packages[0]) + ", " + str(packages[1]) + ", and " + str(packages[2]) + ", the largest number of McNuggets that"
print "cannot be bought in exact quantity is " + str(bestSoFar) + "."

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

from math import *

# pt. 1

primelist = [2]
candnum = 3
primecount = 1000

while len(primelist) < primecount :

    cantbeprime = 0
    
    for i in range (len(primelist)) :

        if candnum % primelist[i] == 0 :
            cantbeprime = 1

    if cantbeprime == 0 :
        primelist.append(candnum)

    candnum += 2

print "The 1000th prime number is", str(primelist[primecount - 1])


# pt. 2

primelist = [2]
candnum = 3
lptotal = 0

x = raw_input ("Enter upper bound (n): ")
primecount = int(x)

while len(primelist) < primecount :

    cantbeprime = 0
    
    for i in range (len(primelist)) :

        if candnum % primelist[i] == 0 :
            cantbeprime = 1

    if cantbeprime == 0 :
        primelist.append(candnum)

    candnum += 2

for i in range(primecount) :

    lptotal += log(primelist[i])

print "Sum of the logs of the primes:", lptotal
print "Number of primes:", primecount
print "Ratio:", lptotal / primecount

jbuck0 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1
# Problem Set 0

firstname = raw_input ("Enter your first name: ")
lastname = raw_input ("Enter your last name: ")
print firstname, lastname

jbuck0 1 year ago