From: Baba on
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?


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 True
return False

truelist=[]
falselist=[]
for n_nuggets in range(30):
result = can_buy(n_nuggets)
if result==True:
truelist=truelist+[n_nuggets,]
else:
falselist=falselist+[n_nuggets,]

print 'true',truelist
print 'false',falselist


tnx
Baba
From: Baba on
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?


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 True
return False

truelist=[]
falselist=[]
for n_nuggets in range(30):
result = can_buy(n_nuggets)
if result==True:
truelist=truelist+[n_nuggets,]
else:
falselist=falselist+[n_nuggets,]

print 'true',truelist
print 'false',falselist


tnx
Baba
From: Ian Kelly on
On Fri, Aug 13, 2010 at 12:25 PM, Baba <raoulbia(a)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?

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.