Shemmerson


Joined 4 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

Problem set 2

# Problem set 2.1a
# Shemmerson

# Show that it is possible to buy exactly 50, 51, 52, 53, 54, and 55 McNuggets, by finding
# solutions to the Diophantine equation.

a = 6
b = 9
c = 20

for n in range(50, 56):
    for d in range(0, n):
        for e in range(0, n):
            for f in range(0, n):
                if a*d + b*e + c*f == n:
                    print d, 'a', '+', e, 'b', '+', f, 'c', '=', n

# Substitute 

#                   for x in range (56, 66):
#                        if n + a == x:
#                           print n, '+', a, '=', x
#                       if n + b == x:
#                            print n, '+', b, '=', x

# for 

#                print d, 'a', '+', e, 'b', '+', f, 'c', '=', n

# To use given solutions to solve range (55, 66)





# Problem set 2.1b
# Shemmerson

# Once the equation is satisfied for x, x +1 ....x +5 then all further answers are 
# multiples of the same values.



# Problem set 2.3
# Shemmerson

# Shows largest number of nuggets that cannot be bought in an exact quantity. 

nugget=[]
ctr=0
n=0


for n in range (1,50): 
    test = False 
    for d in range (0,n):  
        for e in range (0,n):
            for f in range (0,n):
                if (6*d) + (9*e) + (20*f) == n:
                    test = True
                


    if test == True:
        ctr +=1
        if ctr > 5:
            print "Largest exact quantity is",nugget[-1]
    else:
        nugget.append(n)
        ctr = 0


# Problem set 2.4
# Shemmerson

# Same as above with added user control over values 

bestSoFar = []
packages = (6,9,20)
ctr = 0
n=0

for n in range(1, 100): 
    test = False
    for a in range(0,n):
        for b in range(0,n):
            for c in range(0,n):
                if (packages[0]*a) + (packages[1]*b) + (packages[2]*c) == n:
                    test = True


    if test == True:
        ctr += 1
        if ctr == 6:
            print bestSoFar[-1], "is the largest quantity not purchasable in 6,9,20 packages"
            print "............................................................"
            print "Enter your own quantities to find largest quantity not divisable:"
            bestSoFar2 = []
            ctr1 = 0
            n1=0
            x = int(raw_input ("First: "))
            y = int(raw_input ("Second: "))
            z = int(raw_input ("Third: "))
            packages = (x,y,z)
            for n1 in range(1, 50): 
                test = False
                for a in range(0,n1):
                    for b in range(0,n1):
                        for c in range(0,n1):
                            if (packages[0]*a) + (packages[1]*b) + (packages[2]*c) == n1:
                                test = True


                if test == True:
                    ctr1 += 1
                    if ctr1 == 6:
                        print bestSoFar2[-1], "is the largest exact quantity not purchasable in", + x, ",", y, "and/or", z, "packages"
                        

                else:
                    bestSoFar2.append(n1)
                    ctr1 = 0
    else:
        bestSoFar.append(n)
        ctr = 0

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

Ps1a

Ps1b

# Problem set 1a
# Name: Shemmerson
# Collaborators: CuriousReef
# Time: 2 Hrs


#finds 1000th prime

y = 1000
x=2
count=1
print "Finding 1000th prime"
while count<=y:
    prime=True
    for test in range (2, x):
            if x%test == 0:
                prime=False
    if prime==True:
            count = count + 1
            print x,
    if count<=y:
            x = x + 1
print
print `x` + " is the " + `y` + "th prime" 


#Problem set 1b
# Name:Shemmerson
# Collaborators: CuriousReef
# Time: .30 Hrs

#finds and prints all primes to 1000 + sum of logs

import math
x = 2
count = 1
log = 0
y = 1000
print "Finding 1000th prime."
while count<=y:
        prime=True
        for test in range(2,x):
                if x%test ==0:
                        prime=False
        if prime==True:
                count += 1
                log = log + math.log(x)
                print x
        if count <=y:
                x = x + 1
print `x` + " is the " + `y` + "th prime"
print `count-1` + " is the total log count"
print `log` + " is the sum of the logs"

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

First assignment for MIT 6.00 OpenCourseWare

#Problem set 0
#Name: Shemmerson
#Time: 0.10

#ask for and print out a users last and first names

L = raw_input('Please enter your last name: ')
F = raw_input('Please enter your first name: ')
print F + ' ' + L


Shemmerson 4 months ago