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 2a
#Michael
a=6
b=9
c=20
candidate=0
bestSoFar=1
for n in range(1,50):
for i in range(0,n/a+1):
for j in range(0,n/b+1):
for k in range(0,n/c+1):
if a*i+b*j+c*k==n:
break
if a*i+b*j+c*k==n:
break
if a*i+b*j+c*k==n:
break
if a*i+b*j+c*k==n:
candidate+=1
else:
candidate=0
bestSoFar=n
if candidate==6:
break
print 'Largest number of McNuggets that cannot be bought in exact quantity: '+str(bestSoFar)
#Problem Set 2b
#Michael
bestSoFar = 0
packages = (2,4,6)
a=packages[0]
b=packages[1]
c=packages[2]
for n in range(1, 150):
for i in range(0,n/a+1):
for j in range(0,n/b+1):
for k in range(0,n/c+1):
if a*i+b*j+c*k==n:
break
if a*i+b*j+c*k==n:
break
if a*i+b*j+c*k==n:
break
if a*i+b*j+c*k==n:
candidate+=1
else:
candidate=0
bestSoFar=n
if candidate==a:
break
if candidate<a:
print 'The largest number of McNuggets that cannot be bought in exact quantity is greater than 150.'
else:
print 'Given package sizes '+str(a)+', '+str(b)+', and '+str(c)+', the largest number of McNuggets that cannot be bought in exact quantity is: '+str(bestSoFar)
mgoff11
4 days ago
|
 |
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
#Problem Set 1
#Michael
prime = 3
count = 1
divisor = 2
while count<1000:
while divisor<prime:
if prime%divisor == 0:
divisor = prime+1
else: divisor = divisor+1
if divisor == prime:
count+=1 #same as count=count+1
prime+=2
divisor=2
print 'The 1000th prime is: ',prime-2
from math import*
prime = 3
divisor = 2
n = 1000
logsum = log(2)
while prime<n-1:
while divisor<prime:
if prime%divisor == 0:
divisor = prime+1
else: divisor = divisor+1
if divisor == prime:
logsum+=log(prime)
prime+=2
divisor=2
print 'The sum of the logarithms of all the primes less than n is ', logsum
print 'The number n is ', n
print 'The ratio of the sum of the logarithms to n is ', logsum/n
mgoff11
1 year ago
|
 |
|
|
|