looping through possible combinations of McNuggets packs of 6, 9 and 20

Thomas Jollans thomas at jollybox.de
Wed Aug 11 17:15:45 EDT 2010


On Wednesday 11 August 2010, it occurred to Baba to exclaim:
> level: beginner
> 
> exercise: given that packs of McNuggets can only be bought in 6, 9 or
> 20 packs, write an exhaustive search to find the largest number of
> McNuggets that cannot be bought in exact quantity.

The MacDonald's at Nuremberg central station once sold me 25 in a 20-pack. So 
this won't work.

> 
> exercise source:
> http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00
> -introduction-to-computer-science-and-programming-fall-2008/assignments/pse
> t2.pdf
> 
> please help me write this code
> 
> i believe it's something along the lines of this:
> 
> c=0
> sol=[]
> for n in range (0,10):
>  for a in range (0,10):
>   for b in range (0,10):
>    for c in range (0,10):
>     sol=6*a+9*b+20*c
>     if sol!=n:
>      c+=1
>     if c==6:
>      print sol



More information about the Python-list mailing list