I think you’re expressing the question wrong. You are looking for all combinations of integers that sum to a given integer.

That said, I don’t know how to do this without resorting to writing a disgusting recursion myself, but I would be interested to hear good suggestions.

Here’s my quick hack:

```
function combinations!(list, root, N)
if iszero(N)
return push!(list, root)
end
start = isempty(root) ? 1 : last(root)
for n = start:N
arr = vcat(root, n)
combinations!(list, arr, N-n)
end
end
function combinations(N)
list = Vector{Int64}[]
combinations!(list, Int64[], N)
return list
end
```

~~Note, this does include duplicates, so ~~`combinations(3)`

returns `[[1, 1, 1], [1, 2], [2, 1], [3]]`

. Could probably be amended but I don’t feel like it. Nvm I fixed it. Just use `start=1`

if you prefer to include duplicates. And `last(root) + 1`

if you want to exclude solutions with non-unique numbers.