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

2010-08-14 Thread gslindstrom
On Aug 12, 4:33 am, Paul Rubin wrote: > Baba writes: > > 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. > > Is that a homework problem?  Hint: first

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

2010-08-13 Thread News123
On 08/13/2010 10:57 AM, Martin P. Hellwig wrote: > SPOILER ALTER: THIS POST CONTAINS A POSSIBLE SOLUTION > > On 08/12/10 21:41, News123 wrote: > >> On 08/12/2010 09:56 PM, Martin P. Hellwig wrote: >>> On 08/11/10 21:14, Baba wrote: >>> >>> >>> How about rephrasing that question in your mind firs

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

2010-08-13 Thread MRAB
Martin P. Hellwig wrote: On 08/13/10 10:46, Peter Otten wrote: Martin P. Hellwig wrote: SPOILER ALTER: THIS POST CONTAINS A POSSIBLE SOLUTION No it wasn't :-) which should be 1*9 + 2*6 What am I missing? Aah interesting, 21 % 9 returns 3 instead of 12, which makes sense of course. I gu

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

2010-08-13 Thread Martin P. Hellwig
On 08/13/10 10:46, Peter Otten wrote: Martin P. Hellwig wrote: SPOILER ALTER: THIS POST CONTAINS A POSSIBLE SOLUTION No it wasn't :-) which should be 1*9 + 2*6 What am I missing? Aah interesting, 21 % 9 returns 3 instead of 12, which makes sense of course. I guess the algorithm has to b

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

2010-08-13 Thread Martin P. Hellwig
SPOILER ALTER: THIS POST CONTAINS A POSSIBLE SOLUTION On 08/12/10 21:41, News123 wrote: On 08/12/2010 09:56 PM, Martin P. Hellwig wrote: On 08/11/10 21:14, Baba wrote: How about rephrasing that question in your mind first, i.e.: For every number that is one higher then the previous one*:

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

2010-08-12 Thread News123
On 08/12/2010 09:56 PM, Martin P. Hellwig wrote: > On 08/11/10 21:14, Baba wrote: > > > 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

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

2010-08-12 Thread Martin P. Hellwig
On 08/11/10 21:14, Baba wrote: 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 exac

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

2010-08-12 Thread MRAB
Baba wrote: Hi News123 Thank You for helping me out. Indeed i am not looking for the code but rather for hints that direct my reasoning as well as hints as to how to write basic programs like this. You have broken down the approach into 2 parts. I have tried to solve part 1 but i'm not quite th

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

2010-08-12 Thread Brian Victor
Baba wrote: > def can_buy(n_nuggets): [snip] > can_buy(55) > > as you can see i am trying to loop through all combinations of values > bewtween 1 and n_nuggets and when the equation resolves it should > return True, else it should return False. > > I was hoping that when i then call my function and

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

2010-08-12 Thread Baba
Hi News123 Thank You for helping me out. Indeed i am not looking for the code but rather for hints that direct my reasoning as well as hints as to how to write basic programs like this. You have broken down the approach into 2 parts. I have tried to solve part 1 but i'm not quite there yet. Here'

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

2010-08-12 Thread News123
On 08/11/2010 10:14 PM, Baba wrote: > 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. > > exercise source: > http://ocw.mit.edu/cours

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

2010-08-12 Thread MRAB
Steven D'Aprano wrote: On Wed, 11 Aug 2010 13:14:35 -0700, Baba wrote: 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. Is this a trick q

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

2010-08-12 Thread News123
Hi Steven, On 08/12/2010 01:37 AM, Steven D'Aprano wrote: > On Wed, 11 Aug 2010 13:14:35 -0700, Baba wrote: > >> 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 cann

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

2010-08-11 Thread Steven D'Aprano
On Wed, 11 Aug 2010 13:14:35 -0700, Baba wrote: > 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. Is this a trick question? I'd lik

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

2010-08-11 Thread News123
As said in the instructions. if you find six consecutive numbers, that can be bough in exact quantity, then you know, that all bigger numbers can also be bought in exact quantity. I would do a brute force approach first I would create one function, which will try to find out, whether one can