Advertisement
Guest User

Untitled

a guest
Mar 4th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def nuggetguide(target):
  2.     """For a given number, tells you how many of each nugget packages to buy to add up to n"""
  3.     S=0#all initial values at zero
  4.     M=0
  5.     L=0
  6.     for L in range(0,target/20+1):#the large box will have at least 20 pieces so...
  7.         for M in range(0,target/9+1):
  8.             for S in range(0,target/6+1):
  9.                 if target == S*6 + M*9 + L*20:#then we have our answer.
  10.                     return (S, M, L)#return the answer
  11.     return "No solutions"#if the whole thing runs and it doesn't find an answer, return No solutions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement