Let \$S \subset \mathbb N_{\geq0}\$ be a subset of the nonnegative integers, and let $$ S^{(k)} = \underbrace{S + S + \dots + S}_{k\ \textrm{times}} = \{ a_1 + a_2 + \dots + a_k : a_i \in S\}. $$
For example, $$\begin{align} \{1,2,3\}^{(2)} &= \{1+1, 1+2, 1+3, 2+1, 2+2, 2+3, 3+1, 3+2, 3+3\}\\ &=\{2,3,4,5,6\} \end{align}$$
If \$S\$ contains \$n\$ elements, then \$S^{(k)}\$ contains at most \$\binom{n+k-1}{k} = \frac{(n + k - 1)!}{(n-1)!k!}\$ distinct elements. If \$S^{(k)}\$ contains this number of distinct elements, we call it \$k\$-maximal. The set \$S = \{1,2,3\}\$ given in the example above is not \$2\$-maximal because \$1 + 3 = 2 + 2\$.
Challenge
Given a positive integer k
, your task is to return the lexicographically earliest infinite list of nonnegative integers such that for every \$n\$ the set consisting of the first \$n\$ terms of \$S\$ is \$k\$-maximal.
You can return a literal (infinite) list/stream, you can provide function that takes a parameter i
and returns the \$i\$th element of the list, or you can give any other reasonable answer.
This is code-golf so shortest code wins.
Test Data
k | S^(k)
---+------------------------------------------------------------
1 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
2 | 0, 1, 3, 7, 12, 20, 30, 44, 65, 80, 96, ...
3 | 0, 1, 4, 13, 32, 71, 124, 218, 375, 572, 744, ...
4 | 0, 1, 5, 21, 55, 153, 368, 856, 1424, 2603, 4967, ...
5 | 0, 1, 6, 31, 108, 366, 926, 2286, 5733, 12905, 27316, ...
6 | 0, 1, 7, 43, 154, 668, 2214, 6876, 16864, 41970, 94710, ...
For \$k=2\$ , this should return OEIS sequence A025582.
For \$k=3\$ , this should return OEIS sequence A051912.
k
but then that stops working. \$\endgroup\$k
andi
, output thei
-th value in sequencek
? \$\endgroup\$