How to choose a set of numbers such that sum of any combination of numbers in that set yields a unique result?

168 Views Asked by At

I don't remember whether it was VLC or Utorrent exactly but there was a settings page wherein you could choose:

Option A (3) Option B (5) Option C (7)

The way you would choose these options was by adding the corresponding numbers and typing it down. If you type 12 for example, it would know you have chosen B and C. Similarly 15 implies all three options.

I tried to make my own version of this by taking first 6 primes

A = 3 B = 5 C = 7 D = 11 E = 13 F = 15

But there was a discrepancy when the result was 18. It could either mean C + D or it could mean B + E.

How to choose a set of numbers such that sum of any combination of numbers in that set yields a unique result?

1

There are 1 best solutions below

2
On BEST ANSWER

The usual way to do this is to use powers of two. Then each summand corresponds to a set bit in the binary representation of the sum, so you can readily and uniquely reconstruct which summands were used from that binary representation.