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

2010-08-18 Thread cbr...@cbrownsystems.com
On Aug 18, 11:50 am, John Posner wrote: > On 8/18/2010 1:38 PM, cbr...@cbrownsystems.com wrote: > > >>> To go the other way, if d = 1, then there exists integers (not > >>> neccessarily positive) such that > > >>> a*x + b*y + c*z = 1 > > That fact is non-trivial, although the proof isn't *too* har

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

2010-08-18 Thread John Posner
On 8/18/2010 1:38 PM, cbr...@cbrownsystems.com wrote: To go the other way, if d = 1, then there exists integers (not neccessarily positive) such that a*x + b*y + c*z = 1 That fact is non-trivial, although the proof isn't *too* hard [1]. I found it interesting to demonstrate the simpler cas

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

2010-08-18 Thread cbr...@cbrownsystems.com
On Aug 18, 10:52 am, Baba wrote: > Hi Chas > > Thanks for that and i agree on your last remark :) > > re the number of required consecutive passes required: > > The number of required consecutive passes is equal to the smallest > number because after that you can get any amount of nuggets by just

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

2010-08-18 Thread Baba
Hi Chas Thanks for that and i agree on your last remark :) re the number of required consecutive passes required: The number of required consecutive passes is equal to the smallest number because after that you can get any amount of nuggets by just adding the smallest nugget pack to some other n

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

2010-08-18 Thread cbr...@cbrownsystems.com
On Aug 17, 2:44 pm, Baba wrote: > On Aug 16, 6:28 pm, "cbr...@cbrownsystems.com" > > wrote: > > First, suppose d = gcd(x, y, z); then for some x', y', z' we have that > > x = d*x', y = d*y', z = d*z'; and so for any a, b, c: > >    could you explain the notation? > >    what is the difference btw

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

2010-08-18 Thread News123
On 08/17/2010 11:44 PM, Baba wrote: > On Aug 16, 6:28 pm, "cbr...@cbrownsystems.com" > wrote: > >> First, suppose d = gcd(x, y, z); then for some x', y', z' we have that >> x = d*x', y = d*y', z = d*z'; and so for any a, b, c: >> > > >could you explain the notation? > >what is the diff

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

2010-08-17 Thread Baba
On Aug 16, 6:28 pm, "cbr...@cbrownsystems.com" wrote: > First, suppose d = gcd(x, y, z); then for some x', y', z' we have that > x = d*x', y = d*y', z = d*z'; and so for any a, b, c: > could you explain the notation? what is the difference btw x and x' ? what is x = d*x', y supposed

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

2010-08-17 Thread Giacomo Boffi
Paul Rubin writes: > 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? yes, and no it was a homework p

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

2010-08-16 Thread cbr...@cbrownsystems.com
On Aug 16, 11:04 am, Baba wrote: > Hi Chas, Roald, > > These are all complicated formula that i believe are not expected at > this level. If you look at the source (see my first submission) you > will see that this exercise is only the second in a series called > "Introduction to Programming". The

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

2010-08-16 Thread John Posner
On 8/16/2010 4:18 PM, Baba wrote: packages=[2,103,105] min_size=min(packages[0],packages[1],packages[2]) or: min_size = min(packages) -John -- http://mail.python.org/mailman/listinfo/python-list

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

2010-08-16 Thread Baba
well i still believe that the key is the smallest sized pack and there's no need to go into higher mathematics to solve this problem. I think below code works within the limits of the exercise which states to look at a maximum range of 200 in order not to search forever. packages=[2,103,105] min_s

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

2010-08-16 Thread Giacomo Boffi
Baba writes: > Hi Mel, > > indeed i thought of generalising the theorem as follows: > If it is possible to buy n, n+1,~, n+(x-1) sets of McNuggets, for some > x, then it is possible to buy any number of McNuggets >= x, given that > McNuggets come in x, y and z packs. > > so with diophantine_nugge

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

2010-08-16 Thread Mel
Baba wrote: [ ... ] > Now, i believe that the number of consecutive passes required to make > this work is equal to the smallest number of pack sizes. So if we have > packs of (9,12,21) the number of passes needed would be 9 and the > theorem would read > > "If it is possible to buy n,n+1,n+2,...n

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

2010-08-16 Thread Baba
Hi Chas, Roald, These are all complicated formula that i believe are not expected at this level. If you look at the source (see my first submission) you will see that this exercise is only the second in a series called "Introduction to Programming". Therefore i am convinced that there is a much si

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

2010-08-16 Thread Ian Kelly
On Mon, Aug 16, 2010 at 12:43 PM, Roald de Vries wrote: >>> I'm pretty sure that if there's no common divisor for all three (or more) >>> packages (except one), there is a largest unpurchasable quantity. That >>> is: ∀ >>> i>1: ¬(i|a) ∨ ¬(i|b) ∨ ¬(i|c), where ¬(x|y) means "x is no divider of y" >>

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

2010-08-16 Thread cbr...@cbrownsystems.com
On Aug 16, 1:23 am, Roald de Vries wrote: > On Aug 15, 2010, at 11:51 PM, Ian Kelly wrote: > > > > > On Sun, Aug 15, 2010 at 4:36 PM, Baba wrote: > >> Hi Mel, > > >> indeed i thought of generalising the theorem as follows: > >> If it is possible to buy n, n+1,…, n+(x-1) sets of McNuggets, for   >

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

2010-08-16 Thread Roald de Vries
On Aug 16, 2010, at 5:04 PM, Ian Kelly wrote: On Mon, Aug 16, 2010 at 4:23 AM, Roald de Vries wrote: I suspect that there exists a largest unpurchasable quantity iff at least two of the pack quantities are relatively prime, but I have made no attempt to prove this. That for sure is not co

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

2010-08-16 Thread Ian Kelly
On Mon, Aug 16, 2010 at 11:04 AM, Ian Kelly wrote: > On Mon, Aug 16, 2010 at 4:23 AM, Roald de Vries wrote: >>> I suspect that there exists a largest unpurchasable quantity iff at >>> least two of the pack quantities are relatively prime, but I have made >>> no attempt to prove this. >> >> That f

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

2010-08-16 Thread Ian Kelly
On Mon, Aug 16, 2010 at 4:23 AM, Roald de Vries wrote: >> I suspect that there exists a largest unpurchasable quantity iff at >> least two of the pack quantities are relatively prime, but I have made >> no attempt to prove this. > > That for sure is not correct; packs of 2, 4 and 7 do have a large

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

2010-08-16 Thread Roald de Vries
On Aug 15, 2010, at 11:51 PM, Ian Kelly wrote: On Sun, Aug 15, 2010 at 4:36 PM, Baba wrote: Hi Mel, indeed i thought of generalising the theorem as follows: If it is possible to buy n, n+1,…, n+(x-1) sets of McNuggets, for some x, then it is possible to buy any number of McNuggets >= x, give

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

2010-08-15 Thread Ian Kelly
On Sun, Aug 15, 2010 at 4:36 PM, Baba wrote: > Hi Mel, > > indeed i thought of generalising the theorem as follows: > If it is possible to buy n, n+1,…, n+(x-1) sets of McNuggets, for some > x, then it is possible to buy any number of McNuggets >= x, given that > McNuggets come in x, y and z packs

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

2010-08-15 Thread Baba
Hi Mel, indeed i thought of generalising the theorem as follows: If it is possible to buy n, n+1,…, n+(x-1) sets of McNuggets, for some x, then it is possible to buy any number of McNuggets >= x, given that McNuggets come in x, y and z packs. so with diophantine_nuggets(7,10,21) i would need 7 pa

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

2010-08-15 Thread Mel
Baba wrote: > Hi All, > > @Emile tnx for spotting the mistake. Should have seen it myself. > > @John & Ian i had a look around but couldn't find a general version of > below theorem > If it is possible to buy x, x+1,…, x+5 sets of McNuggets, for some x, > then it is possible to buy any number

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

2010-08-15 Thread Baba
Hi All, @Emile tnx for spotting the mistake. Should have seen it myself. @John & Ian i had a look around but couldn't find a general version of below theorem If it is possible to buy x, x+1,…, x+5 sets of McNuggets, for some x, then it is possible to buy any number of McNuggets >= x, given that M

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

2010-08-15 Thread John Posner
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 argumen

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

2010-08-15 Thread Ian Kelly
On Sun, Aug 15, 2010 at 9:58 AM, Emile van Sebille wrote: > On 8/15/2010 8:44 AM Baba said... >> >> Hi John, >> >> Thanks for your submission! I've improved a lot and everone's help so >> far has been thrilling and is very good for my self-study >> motivation :) >> >> ok so i think i'm clear on ho

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

2010-08-15 Thread Emile van Sebille
On 8/15/2010 8:44 AM Baba said... Hi John, Thanks for your submission! I've improved a lot and everone's help so far has been thrilling and is very good for my self-study motivation :) ok so i think i'm clear on how to approach this problem and on how to write basic but clean Python code to sol

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

2010-08-15 Thread Baba
Hi John, Thanks for your submission! I've improved a lot and everone's help so far has been thrilling and is very good for my self-study motivation :) ok so i think i'm clear on how to approach this problem and on how to write basic but clean Python code to solve it. The next step is to generali

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

2010-08-15 Thread Baba
Hi John, Thanks for your submission! I've improved a lot and everone's help so far has been thrilling amd is very good for my self-study motivation :) ok so i think i'm clear on how to approach this problem and on how to write basic but clean Python code to solve it. The next step is to generali

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

2010-08-14 Thread John Posner
On 8/14/2010 10:52 AM, Baba wrote: for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[]

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

2010-08-14 Thread MRAB
Baba wrote: On Aug 13, 8:25 pm, Ian Kelly wrote: 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. Hi Ian, Thanks for

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

2010-08-14 Thread Ian Kelly
On Sat, Aug 14, 2010 at 8:52 AM, Baba wrote: > my code is probably not elegant but a huge step forward from where i > started: > > def can_buy(n_nuggets): >   for a in range (0,n_nuggets): >       for b in range (0,n_nuggets): >           for c in range (0,n_nuggets): >               #print "tryin

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

2010-08-14 Thread member thudfoo
On 8/14/10, Baba wrote: > On Aug 13, 8:25 pm, Ian Kelly wrote: > >> 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 >> sequenti

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

2010-08-14 Thread Mel
Baba wrote: > def can_buy(n_nuggets): >for a in range (0,n_nuggets): >for b in range (0,n_nuggets): >for c in range (0,n_nuggets): >#print "trying for %d: %d %d %d" % (n_nuggets,a,b,c) >if 6*a+9*b+20*c==n_nuggets: >return

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

2010-08-14 Thread Baba
On Aug 13, 8:25 pm, Ian Kelly wrote: > 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. Hi Ian, Thanks for stating

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

2010-08-13 Thread News123
Hi BAba, On 08/13/2010 09:25 PM, Ian Kelly wrote: > On Fri, Aug 13, 2010 at 12:25 PM, Baba 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 quantitie

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

2010-08-13 Thread John Posner
On 8/13/2010 6:25 AM, Roald de Vries wrote: On Aug 12, 2010, at 10:51 PM, John Posner wrote: On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force tgt = 120 # thanks, Dave Angel Anytime, but I'm not Dave Angel.

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

2010-08-13 Thread News123
Roald, What would your solution be if you weren't allowed to 'know' that 120 is an upper limit. Assume you were only allowed to 'know', that you won't find any other amount, which can't be bought A AOON A you found six solutions in a row? I have a rather straightforward solution trying from 0

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

2010-08-13 Thread Ian Kelly
On Fri, Aug 13, 2010 at 12:25 PM, Baba 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, 1

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

2010-08-13 Thread Baba
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,

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

2010-08-13 Thread Baba
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,

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

2010-08-13 Thread Roald de Vries
On Aug 13, 2010, at 12:25 PM, Roald de Vries wrote: My previous algorithm was more efficient, but for those who like one- liners: [x for x in range(120) if any(20*a+9*b+6*c == x for a in range(x/20) for b in range(x/9) for c in range(x/6))][-1] OK, I did some real testing now, and there's s

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

2010-08-13 Thread Roald de Vries
On Aug 12, 2010, at 10:51 PM, John Posner wrote: On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force tgt = 120 # thanks, Dave Angel Anytime, but I'm not Dave Angel. My previous algorithm was more efficient, b

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

2010-08-13 Thread Peter Otten
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 first, i.e.: >>> >>> For ev

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

2010-08-12 Thread Lawrence D'Oliveiro
In message , Jean- Michel Pichavant wrote: > for mcNugget in range(0,10): > sendTo(trashbin) Ah, but should that be mcNugget.sendTo(trashbin) or trashbin.insert(mcNugget) ? -- http://mail.python.org/mailman/listinfo/python-list

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

2010-08-12 Thread John Posner
On 8/12/2010 6:31 PM, News123 wrote: candidate_box_counts = product( xrange(target/box_sizes[0] + 1), xrange(target/box_sizes[1] + 1), xrange(target/box_sizes[2] + 1), ) Couldn't this be rewritten as: candidate_box_counts = product( * [ xrange

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

2010-08-12 Thread News123
On 08/12/2010 10:51 PM, John Posner wrote: > On 8/12/2010 9:22 AM, Dave Angel wrote: >>> >>> Now you have to find the largest number below 120, which you can >>> easily do with brute force > > Dept of overkill, iterators/generators division ... > > -John > > #-- > from itertools

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

2010-08-12 Thread John Posner
On 8/12/2010 9:22 AM, Dave Angel wrote: Now you have to find the largest number below 120, which you can easily do with brute force Dept of overkill, iterators/generators division ... -John #-- from itertools import imap, product, ifilter from operator import mul box_sizes =

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

2010-08-12 Thread News123
One more small tip to verify whether your code is working: On 08/12/2010 10:28 PM, News123 wrote: > Hi Baba, Your code, but returning the result as suggested in my preious post: > def can_buy(n_nuggets): >for a in range (1,n_nuggets): >for b in range (1,n_nuggets): >for

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

2010-08-12 Thread News123
Hi Baba, The last tips should really help you getting started: for testing your function you could do: Below your uncorrected code and a test for it def can_buy(n_nuggets): for a in range (1,n_nuggets): for b in range (1,n_nuggets): for c in range (1,n_nuggets):

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

2010-08-12 Thread Roald de Vries
On Aug 12, 2010, at 9:02 PM, Peter Otten wrote: Baba wrote: 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

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

2010-08-12 Thread Peter Otten
Baba wrote: > 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 Dave Angel
Roald de Vries wrote: On Aug 12, 2010, at 11: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

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

2010-08-12 Thread Roald de Vries
On Aug 12, 2010, at 11: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 con

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

2010-08-12 Thread Paul Rubin
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 convince yourself that a largest number actually

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

2010-08-12 Thread Jean-Michel Pichavant
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/courses/electrical-engineering-and-computer

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

2010-08-11 Thread Thomas Jollans
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 Nur

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

2010-08-11 Thread Baba
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/courses/electrical-engineering-and-computer-science/6-00-