looping through possible combinations of McNuggets packs of 6, 9 and 20
John Posner
jjposner at optimum.net
Sun Aug 15 12:24:42 EDT 2010
On 8/15/2010 11:38 AM, Baba wrote:
In addition to the points that Emile and Ian made ...
>
> def diophantine_nuggets(x,y,z):
> cbc=0 #cbc=can_buy counter
> packages =[x,y,z]
You can take advantage of a nifty "syntax convenience feature" here.
Instead of loading all of the function's arguments into a list
"manually", you can make it happen automatically:
def diophantine_nuggets(x,y,z):
cbc = 0
packages =[x,y,z]
... becomes ...
def diophantine_nuggets(*packages):
cbc = 0
The asterisk (*) in the function's signature does the trick.
> for n_nuggets in range(50):
Careful -- in the general case, you might need to search beyond 50 for
your answer!
Best,
John
More information about the Python-list
mailing list