user
Suppose you had an infinite length ruler with which you wanted to be able to measure any positive integer unit length, but which has no extraneous tic marks or repeated intervals. Assume the ruler has a boundary at zero, but extends toward positive infinity to remove any issues of mirrored intervals. Assume there is a tic mark at zero.

* :   To measure a **1** unit length, you need a tic mark at 1 unit in. Whenever you add a tick to the ruler, you need to add that interval to the sequence. (**Sequence: 1**)

* :   To measure a **2** unit length, you need to have tics two units apart. If you add one two units in, you will have two 1 unit intervals, which is not allowed. Instead you need to put a tic mark 2 units from the 1. This will allow measuring both 1 unit lengths and 2 unit lengths with no repeated lengths or extraneous tics. (**Sequence: 1, 2**)

* :   To measure a **3** unit length, you have a 1 unit interval and 2 unit interval directly next to one another. You can measure a 3 unit length by utilizing the 1 and 2 contiguous intervals. There is no need to have a dedicated 3 unit interval. No added tic. (**Sequence: 1, 2**)

* :   To measure a **4** unit interval; there is no way to combine the 1 and 2 unit intervals to yield 4, so you need to add another tic, 4 units from the previous (2). (**Sequence: 1, 2, 4**)

* :   **5** units; There is no way to form a 5 unit contiguous interval, so add a tic at 5. (**Sequence: 1, 2, 4, 5**)

* :   **6** units; The contiguous units 2 and 4 make a 6 unit interval; no tic needed. (**Sequence: 1, 2, 4, 5**)

* :   **7** units; The contiguous units 1, 2 and 4 make a 7 unit interval; no tic needed. (**Sequence: 1, 2, 4, 5**)

* :   **8** units; The units 1, 2 and 5 make 8 but they are not contiguous; There is no contiguous group that sums to 8. Add a tic at 8 (**Sequence: 1, 2, 4, 5, 8**)

* :   *and so on...*

The numbers in this sequence, the numbers whose length can not be formed by any contiguous combination of prior elements in the sequence, are known as **Prime numbers of measurement** or sometimes **segmented numbers**. They are often referred to as **MacMahon's prime numbers of measurement** after P. A. MacMahon who was first to publish work studying them. They are not (necessarily) prime in the traditional sense, rather, there is no way to arrive at one by summing previous contiguous elements.

Task

* :   Find and display the first 100 elements of this sequence.

Stretch

* :   Find and display the 1000th element of this sequence.

See also

* OEIS A002048 - Segmented numbers, or prime numbers of measurement
assistant
```
my atomicint $index = 0;
my @prime-measure = 1;

for 2..* -> $next {
    my atomicint $last;
    (0..$index-1).hyper(:10batch).map: -> $start {
        for 1..$index -> $end {
            next if $start == $end;
            last if $next < my $sum = @prime-measure[$start..$end].sum;
            ++⚛$last and last if $sum == $next;
        }
        last if $last
    }
    next if $last;
    @prime-measure.push: $next;
    ++⚛$index;
    last if $index >= 999;
}

put "First 100:\n", @prime-measure[^100]».fmt('%3d').batch(10).join: "\n";

put "\nOne Thousandth: ", @prime-measure.tail;

```

Output:

```
First 100:
  1   2   4   5   8  10  14  15  16  21
 22  25  26  28  33  34  35  36  38  40
 42  46  48  49  50  53  57  60  62  64
 65  70  77  80  81  83  85  86  90  91
 92 100 104 107 108 116 119 124 127 132
133 137 141 144 145 148 150 151 154 158
159 163 165 172 173 174 175 178 180 182
184 187 188 195 198 201 206 207 208 213
219 221 222 226 228 231 233 236 241 242
245 247 248 253 256 262 266 268 272 274

One Thousandth: 3165
```