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

News123 news1234 at free.fr
Fri Aug 13 23:09:30 CEST 2010

```Hi BAba,

On 08/13/2010 09:25 PM, Ian Kelly wrote:
> On Fri, Aug 13, 2010 at 12:25 PM, Baba <raoulbia at gmail.com> wrote:
>> Hi News 123,
>>
>> Ok i'm getting closer. I am able to write code that will output values
>> that can be bought in exact quantity (truelist) and values that cannot
>> be bought in exact quantities.
>>
>> For a range up to 29 i get this:
>> true [6, 9, 12, 15, 18, 20, 21, 24, 26, 27, 29]
>> false [0, 1, 2, 3, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 22, 23, 25,
>> 28]
>>
>> the sixth value that passes the test of having an exact solution is 20
>> so that would mean that the last number i got that cannot be bought in
>> exact quantity is 19
>>
>> that doesn't seem quite right, does it?
As Thomas says:
>
> It's not.  You're not just trying to find the sixth value that can be
> bought in exact quantity, but a sequence of six values that can all be
> bought in exact quantity.  The integers [6, 9, 12, 15, 18, 20] are not
> sequential.

Six True values in a row without a False value n between tells you, that
you can stop searching.

So you that's what you have to write
A piece of code, which

fetches true fals values for 0 to e.g. 200 nuggets
and stops if you had 6 True values in a row.

Think how you do it manually:
you can try this even without the
can_buy function and plug in th can_buy() function  only if you ahve
your detection of 6 True values in a row working.

test_sequence = "0010011011101110111101111111011111"

# below I use the enumerate function.
# rather useful for going through a list AND having a counter value.
# when plugging in your function you can switch back to
# for n_nuggets in xramge(200):

# perhaps here some initialisation for your searching
for i, a_char in enumerat(test_suequence):
print "entry %2d (%s) is %s" % (i,a_char,result)
result = a_char == '1' # result is now true for a '1'
# and false for a '0'
# here some code to determine the length of the sequence
if sequence_length == 6:
print "I found a sequence of 6 and can stop searching"
print "my solution is "

```