# Thread:

1. ## 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

___________________

2. ## 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 $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.

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

Hi

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

4. ## 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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 1, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9435443878173828, "perplexity_flag": "middle"}