Problem. Which set of weights lets a balance measure every integer weight with as few weights as possible?
| Weights may go on | Optimal set | Covers |
|---|---|---|
| one pan only | (binary) | |
| both pans | (balanced ternary): 4 weights cover |
vector<int> balancedTernary(long long w) { // w = sum d_i 3^i, d_i in {-1, 0, 1}: +1 = weight on the other pan, -1 = with the object
vector<int> d;
while (w) { int r = w % 3; if (r == 2) r = -1; d.push_back(r); w = (w - r) / 3; }
return d;
}Proof: balanced ternary covers exactly (3^k − 1)/2
With both pans, each weight contributes , or times its value, so weights give at most signed sums, symmetric around : at most positive values. Balanced ternary shows that the weights achieve every integer in : the digit algorithm takes , replaces by , and continues with , which shrinks and terminates, and the representation is unique. Checked by reconstructing every .