The 4 pieces have weights 1, 3, 9, and 27 pounds. That is, the weights are
3^0, 3^1, 3^2, and 3^3 pounds.
We can compute the balance of the scale (where positive means it is
right-leaning) by multiplying each piece's weight by
- 0 if the piece is on neither side
- 1 if the piece is on the right
- -1 if the piece is on the left
Note that this is just ternary, but each digit is shifted by -1. Since 4
ternary digits uniquely represent the numbers from 0 to 81, shifting this,
we get that for any scale balance between -40 and 40, there is a unique
way to place the weights to get that particular balance.
For instance, to weigh something that is 20 pounds, we first add 40 to get 60,
and write 60 in ternary as
60 = 2 * 3^3 + 0 * 3^2 + 2 * 3^1 + 0 * 3^0.
This means that we put the 3^3 and 3^1 pound weights on the right side, and
the 3^2 and 3^0 pound weights on the left side, so that the right is heavier
than the left by 20 pounds.