Algorithm for finding arrangement of 5 variables in eqn with +/- b/w to satisfy it

Hi all

My friend gave me a riddle (very well known) in which I had to break a 40kg block in 4 pieces ( of integral weight) such that using all those pieces one can measure all weights in range 1 - 40 on a physical balance thingy (I hope that's what its called).

Then we decided to make a python program for it, but we cant find any algorithm to arrange 4 weights (i, j, k, l) and a weight w in equation.

We might be able to do it using regular expressions and built in eval() ... (we just started with the idea but, i feel very confident about it) but that feels like cheating ... or more like a walkthrough ...

It'll be great if someone could point me to the right direction by telling me what kind of algo do stuff like this (not too complex maths please :P)

Thanks in Advance

:)

___________________

Re: Algorithm for finding arrangement of 5 variables in eqn with +/- b/w to satisfy i

It's impossible. With four pieces you can make at most $\displaystyle 2^4 = 16$ different weights.

However, if you are allowed to "subtract" weights (e.g. by using a balance scale and putting one weight on the opposite end) then it's possible. Use 1,3,9,27 kg. This turns out to be a problem involving base 3. Also, 1+3+9+27 = 40.

Re: Algorithm for finding arrangement of 5 variables in eqn with +/- b/w to satisfy i

Hi

Thanks for the quick reply

I did mentioned "with +/- between them" in my Title (I am very bad at explaining my ideas to other people :P )

-can you please explain me how to solve this problem using base 3.

-And also how did you decided to use base 3

-And also some explanation for base 3. I've only read base 10, 2, 8, 16

I know It's a pretty long list so we should start by ME studying a bit more about all the points above. Could you give me links to pages where I can understand all these stuff better and then I'll come back here for more help :D

Thanks for your time

Re: Algorithm for finding arrangement of 5 variables in eqn with +/- b/w to satisfy i

Base 3 works because, for a weight X

*add X

*not use X

*subtract X

If you don't know what base 3 is, it works just like any other base.