Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- ### template of code for Problem 4 of Problem Set 2, Fall 2008
- ###
- bestSoFar = 0
- packages = (6,9,20) # variable that contains package sizes
- smallest = packages[0]
- if packages[1] < packages[0] and packages[1] < packages[2]:
- smallest = packages[1]
- if packages[2] < packages[0] and packages[2] < packages[1]:
- smallest = packages[2]
- #print(smallest)
- maxA = 150 // packages[0]
- maxB = 150 // packages[1]
- maxC = 150 // packages[2]
- #print('Max:', maxA,maxB,maxC)
- combo = 0 #combo is the consecutive number of "impossible" orders
- while combo < (smallest + 1): #if the combo gets above six, than our mission is done
- for n in range(1,150): #all of this is commented in the ps2.py program, everything is the same for the most part
- combination = False
- for a in range(0,maxA+1):
- for b in range(0,maxB+1):
- for c in range(0,maxC+1):
- solution = a*packages[0] + b*packages[1] + c*packages[2]
- if solution == n:
- # print('This number', n, "can be ordered at McDonalds. The combination is:",a,b,c,)
- combination = True
- # combo = 0
- # print('This number', current_number, 'cannot be ordered at McDonalds.')
- if combination == False:
- combo = combo + 1 #only difference is here, impossible combination increases the counter by 1 and sets the current number as the highest impossible order
- # print(combo)
- bestSoFar = n
- if combo > smallest:
- break
- print('Largest number of McNuggets for', packages, 'combination that cannot be bought in exact quantity:', bestSoFar) #printing, as requested
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement