# New Scientist Enigma 1656

I was flipping through an issue of New Scientist over lunch, and came across their Enigma column. It seemed like a pretty simple computational problem, so I thought I’d give it a try. Here’s the problem (link to New Scientist site):

Five integers

I have written down five single-digit positive integers.

The sum of the five integers is divisible by the fifth integer, but not by any of the first four. The sum of the first four integers is divisible by the fourth but not by any of the first three. The sum of the first three integers is divisible by the third but not by either of the first two. The sum of the first two integers is divisible by the second but not by the first.

List the five integers in the order in which I have written them down.

My code follows. It does the problem backwards, starting with a list of all 2-digit combinations, then deleting any that don’t meet the criteria. Then it expands the survivors to three digits, then eliminates any that don’t pass the test, etc. up to five digits.

And the output looks like:

```For length 2
[[2, 1], [3, 1], [4, 1], [4, 2], [5, 1], [6, 1], [6, 2], [6, 3], [7, 1], [8, 1], [8, 2], [8, 4], [9, 1], [9, 3]]
For length 3
[[4, 2, 1], [4, 2, 3], [6, 2, 1], [6, 3, 1], [8, 2, 1], [8, 2, 5], [8, 4, 1], [8, 4, 2], [8, 4, 3], [8, 4, 6], [9, 3, 1], [9, 3, 2], [9, 3, 4]]
For length 4
[[8, 4, 2, 1], [8, 4, 2, 7], [8, 4, 6, 1], [8, 4, 6, 3], [8, 4, 6, 9], [9, 3, 4, 1]]
For length 5
[[8, 4, 6, 3, 1]]
```