Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. ###
  2. ### template of code for Problem 4 of Problem Set 2, Fall 2008
  3. ###
  4.  
  5. bestSoFar = 0
  6. packages = (6,9,20)   # variable that contains package sizes
  7. smallest = packages[0]
  8. if packages[1] < packages[0] and packages[1] < packages[2]:
  9.     smallest = packages[1]
  10. if packages[2] < packages[0] and packages[2] < packages[1]:
  11.     smallest = packages[2]
  12.  
  13. #print(smallest)
  14.  
  15. maxA = 150 // packages[0]
  16. maxB = 150 // packages[1]
  17. maxC = 150 // packages[2]
  18.  
  19. #print('Max:', maxA,maxB,maxC)
  20.  
  21.  
  22.  
  23. combo = 0 #combo is the consecutive number of "impossible" orders
  24. while combo < (smallest + 1): #if the combo gets above six, than our mission is done
  25.     for n in range(1,150): #all of this is commented in the ps2.py program, everything is the same for the most part
  26.         combination = False
  27.         for a in range(0,maxA+1):
  28.             for b in range(0,maxB+1):
  29.                 for c in range(0,maxC+1):
  30.                     solution = a*packages[0] + b*packages[1] + c*packages[2]
  31.                     if solution == n:
  32. #                        print('This number', n, "can be ordered at McDonalds. The combination is:",a,b,c,)
  33.                         combination = True
  34. #                        combo = 0
  35. #        print('This number', current_number, 'cannot be ordered at McDonalds.')
  36.         if combination == False:
  37.             combo = combo + 1 #only difference is here, impossible combination increases the counter by 1 and sets the current number as the highest impossible order
  38. #            print(combo)
  39.             bestSoFar = n
  40.     if combo > smallest:
  41.         break
  42. 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