# Numbers which are not the sum of distinct squares

[Try it online!](https://tio.run/##jVA7TsMwGN5zik9qhraApS4MjVKxcgZEKwN/wJLjJH4gqip7uQSHYGXrUXqRkD@maUcyWIq/t2uy@rbryi3uXBOkJYcc6@P@C6KU9RLzw3eGCe5NoYzyBEdW9ZyqwB89SYrKYiEEa25WSF2DHcZvAobpnewWz1X5pIz0qjJsILUeTZg6dAglFzh1eVj3do/iQugOP6IniWBUE0i4yvpsVNtg4g9nRq9dcmrCqKiDe5ummxmkeYGhD49gNDkXUdJUumxUqALpBnkeQS@VxhUW/brRasmEFqQd9ddaOs@isxdW5ym8JBuwfuB0hnbIiWcdPF4t1ZjjuP@M1a/5Uc/JXPgfAUnbdb8)

**Spoiler:** *(highlight to read)*

Once the longest run of consecutive generated sums is longer the the next square, every number after can be generated by adding the next square to every number in the run. Find the *new* longest run, add the *next* square, etc.

```perl
my @squares = ^∞ .map: *²; # Infinite series of squares

for 1..∞ -> $sq {          # for every combination of all squares
    my @sums = @squares[^$sq].combinations».sum.unique.sort;
    my @run;
    for @sums {
        @run.push($_) and next unless @run.elems;
        if $_ == @run.tail + 1 { @run.push: $_ } else { last if @run.elems > @squares[$sq]; @run = () }
    }
    put grep * ∉ @sums, 1..@run.tail and last if @run.elems > @squares[$sq];
}
```

#### Output:

```
2 3 6 7 8 11 12 15 18 19 22 23 24 27 28 31 32 33 43 44 47 48 60 67 72 76 92 96 108 112 128
```
