Search code examples
algorithmnumberssumsequence

how to construct a sequence of positive integers with a unique sum of any contiguous numbers?


For example: 1,2,4,5 has the following sum:

1,2,4,5

3,6,9

7,11

12

and every sum is unique.

Now, 1,2,3 has the following sum:

1,2,3

3,5

6

and apparently not every sum is unique.

Is there any efficient way to generate similar sequence to the first example with the goal of picking every number as small as possible (not just 1,2,4,8,16...)? I understand I could write a program to perhaps bruteforce this, but I'm just curious can it be done in a better way.


Solution

  • I think what you're looking for here is a Golomb Ruler. If you take the numbers you're describing above as the distance between marks, you've described a Golomb Ruler. When the set of marks on a ruler has no duplicates, as you've described, that's what makes it a Golomb Ruler.

    It appears the standard way to describe a Golomb Ruler is by representing the location of each mark, not the distances between them. Therefore, your 1,2,4,5 would be described as a Golomb Ruler 0-1-3-7-12.

    Quoting Wikipedia:

    Currently, the complexity of finding OGRs of arbitrary order n (where n is given in unary) is unknown. In the past there was some speculation that it is an NP-hard problem. Problems related to the construction of Golomb Rulers are provably shown to be NP-hard, where it is also noted that no known NP-complete problem has similar flavor to finding Golomb Rulers.