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

News123 news1234 at free.fr
Thu Aug 12 16:41:32 EDT 2010


On 08/12/2010 09:56 PM, Martin P. Hellwig wrote:
> On 08/11/10 21:14, Baba wrote:
> <cut>
> 
> How about rephrasing that question in your mind first, i.e.:
> 
> For every number that is one higher then the previous one*:
>     If this number is dividable by:
>         6 or 9 or 20 or any combination of 6, 9, 20
>             than this number _can_ be bought in an exact number
>     else
>         print this number
> 

you are allowed to mix.
15 is neither divisable by 6 nor by nine, but 9 + 6 = 15

I guess, trying to find the result with divisions and remainders is
overly complicated.

Simple brute force trial to find a combination shall be enough.

Also:


if you know for example,
that you can buy 101,102,103,104,105 and 106 nuggets,
then you know, that you can buy any other larger amout of nuggets.

107 = 101 + one box of six
108 = 102 + one box of six
. . .

As soon as you found 6 sequential solutions you can stop searching.








More information about the Python-list mailing list