About Me
No description provided.
Classes
|
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
# Name: TheHedge
# Collaborators: 0
# Time: 05:00:00
# PROBLEM 1
packages = (6,9,20)
def mcComboPossible(n):
Possible = 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:
Possible = True
c += 1
b += 1
a += 1
return Possible
def mcCombo(n):
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:
print 'to get' ,n, 'nuggets, you could buy ' ,a, 'x ', packages[0],' nuggets' ,b, 'x', packages[1],' nuggets, and' ,c, 'x ',packages[2],' nuggets'
c += 1
b += 1
a += 1
numNuggets = int(raw_input('How many nuggets would you like? \n'))
if mcComboPossible(numNuggets) == False:
print 'Sorry, that is not possible!'
else:
mcCombo(numNuggets)
# PROBLEM 3
nCount =0
for a in range (6,100):
if mcComboPossible(a) == True:
nCount +=1
if nCount == 6:
print 'The largest number of McNuggets that cannot be bought in exact quantity is' ,a-6,' \n'
else:
nCount = 0
# PROBLEM 4
limit = 50
def getMcCombos(limit,x,y,z):
Possible = False
for a in range (0,limit):
for b in range (0,limit):
for c in range (0,limit):
if (packages[0]*a) + (packages[1]*b) + (packages[2]*c) ==limit:
Possible = True
c += 1
b += 1
a += 1
return Possible
while getMcCombos(limit,packages[0],packages[1],packages[2]) == True:
limit -=1
getMcCombos(limit,packages[0],packages[1],packages[2])
print 'Given package sizes ', packages[0],',', packages[1], 'and', packages[2],'the largest number of nuggets that connot be bought in the exact quantity is', limit,
TheHedge
1 year ago
|
 |
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
# Problem Set 1
# Name: TheHedge
# Collaborators: 0
# Time: ~03:00:00
# Part A
c = 1 # use this to count the number of primes
a = 3 # test value, starting at 3 as 1 & 2 are primes
d = 1000 # set the number of the prime we want
while (c < d): # only run if the # of primes is less than d
b = a/2 # what is the remainder if divided by 2?
while (b > 1): # if there is no remainder, its not a prime
if a % b == 0: # if it is not a prime...
a = a + 2 # set a to the next odd number
b = a / 2 # what is the remainder if divided by 2?
else: b = b - 1 # a is a prime, so
c = c + 1 # increase the count of primes by 1
a = a + 2 # go to the next odd number
print a - 2 # now that the 1000th prime is known, show its value
# Part B
import math # get the math tools
a = 3
c = 1 # counter
d = int (raw_input("Enter a Number: ")) # user inputs a value
e = math.log(2) # the log of 2, the starting point
while a < d: # only run when primes are less than d
b = 3 # we start with 3
while (b < math.sqrt(a) and a % b <> 0): # do this for values where b < sqrt(a) and for primes
b = b + 2 # set b to the next
if b > math.sqrt(a):
e = e + math.log(a) # add the log of a to e
a = a + 2 # go to the next odd number
print e # the sum of the logs of the primes
print a # the number chosen
r = e / a # calculate the ratio of e to a
print r # print the ratio of e to a
TheHedge
1 year ago
|
 |
|
|
|