May I thank Slippy for holding the fort during my enforced absence, I think she adds a touch of class to the proceedings; speaking of which, I made bail so I could say
Lzzie:Rap:Mark:
WEIGHTS
Rap is correct, however, he could have arrived at the answer more directly had he not abandoned his initial strategy.
As an aside, it's somewhat fortunate that the strategy works, because on the surface, there is nothing that requires 1 to be a weight. The weights must sum to 40, and all integers between 1 and 40 must be uniquely represented by the various sums and differences, but 1 could be covered by 5 and 6 (6-5=1) for example.
To generalize rap's strategy:
Step 1: Start with 1.
Step 2: To get the next weight, double what you've already got and add 1. If the current total weight is X, then the next weight is 2X+1 because 2X+1 - X = X+1.
Step 3: If not finished, go to step 2.
1, 3, 9, 27
Note that these are powers of 3. For a given weight, to determine the arrangement of weights on the balance scale, follow this procedure:
Step 1: Write the desired weight in base 3 (digits are 0, 1, and 2)
Step 2: From right to left: If the current digit is a 0 or a 1, leave it unchanged. If the current digit is a 2, change it to a -1 and add 1 (adhering to base 3 addition rules) to the next digit.
Step 3: If not finished, go to step 2.
Step 4: If a ternary digit for a given weight (1, 3, 9, 27) is 0, it is not used in the weighing. If the digit is 1, place the corresponding weight on the left pan. If the digit is -1, place the corresponding weight on the right pan.
Example: 25 = 0221 base 3
The sequence of digit modifications is:
0 2 2 1 (leave the 1 alone)
0 2 -1 1 (change the 2 to a -1)
1 0 -1 1 (add 1 to the next 2 which results in a carry: 2+1 = 10)
27 goes on the left
9 is not used
3 goes on the right
1 goes on the left
(27+1) - 3 = 25
This works because it leaves the original base 3 number unchanged. When you convert a 2 to a -1, you are subtracting 3 times the place value. By adding one to the next digit, you are adding back 3 times that place value (which in base 3 is the next place value).
Print it out folks, you will never see better!