I’ve got a set of scales, but no weights; I’m making some to weigh from 1mg up to 100g in 1mg steps. I’d like to minimise the number of weights needed. Using a binary sequence (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536mg) gives 17 individual weights and allows unknown masses up to 131.071g. The most efficient algorithm I can come up with gives the correct mass in no more than 17 weighings: with the unknown mass in pan 1, (a) add the heaviest known weight (65526mg) to pan 2; (b) if pan 1 is heavier, add the next lighter weight to pan 2, then go back to (b), otherwise remove the last kmown weight added and add the next lighter mass to pan 1 and go back to (b); repeat until the scales balance. This is basically a maximally efficient successive approximation technique.
I’ve tried using a binary-tree-type search for this (start with the middle weight in pan 2, then pick the mid-point of the heavier or lighter weights depending on whether that’s lighter or heavier than what’s in pan1, etc); that doesn’t work because the unknown mass is the sum of several known weights rather than a single weight (usually). It’s also complicated by the fact that the sequence of masses is exponential rather than linear.
A method alternative to the binary sequence is balanced ternary, where the known masses are powers of 3 (1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147mg) for a total of 12 masses, allowing up to 265.720g (note that not including the 177147mg mass only allows measuring up to 88.573g.) Then the different masses can be found as follows (the unknown mass is in pan 1):
| Total | Pan 1 (with unknown) | |
|---|---|---|
| 1mg | 0mg | 1mg |
| 2mg | 1mg | 3mg |
| 3mg | 0mg | 3mg |
| 4mg | 0mg | 3mg+1mg |
| 5mg | 3mg+1mg | 9mg |
| 6mg | 3mg | 9mg |
etc
I’m trying to find an efficient algorithm for finding any unknown mass (in pan 1) to minimise the total number of weighings (using either binary or balanced ternary, but probably the latter,) but not having as much success as I’d like. I’m multiplying the known weights in pan 1 by -1 for the mathematics, which works, but it’s not really helping.
Has anyone here got any suggestions?