Set of Numbers when added in any combination always produce unique result

1.1k Views Asked by At

What I'm looking for is a set of numbers that when added in any combination they always have a unique sum?

Is this called something? I have searched on google for hours and I'm having a hard time getting a result.

Example Set [8, 16, 32, 64]

8 + 16 = 24

8 + 32 = 40

8 + 64 = 72

8 + 16 + 32 = 56

8 + 16 + 64 = 88

8 + 32 + 64 = 104

8 + 16 + 32 + 64 = 120

16 + 32 = 48

16 + 64 = 80

16 + 32 + 64 = 112

32 + 64 = 96

etc.

Any combination always produces a unique result.

I am working on a software application and I need to store a group of Boolean variables in a single integer field

I thought it would be easy to simply assign an integer value to each variable and sum all the variables that are true and then save that number.

I'm mainly looking to see if this pattern has a name that would make it easier to search for.

1

There are 1 best solutions below

0
On BEST ANSWER

You can use the powers of two, which your example is doing. You can add in $1,2,4$ and have it work, too. This is a property of the binary number system-when the sum is expressed in binary, the bits that are $1$ are the numbers you added.

Of course, you can do it in base $10$ as well, using $1,10,100,1000,10000,$ etc, but the numbers get larger.