We all know how binary conversion works: the sequence of bits
$$ b_1, b_2, ..., b_{n-1}, b_n $$
encodes the number
$$ b_1 \times 2^{n-1} + b_2 \times 2^{n-2} + ... + b_{n-1} \times 2^1 + b_n \times 2^0 $$
This gives an unambiguous representation when we limit all bits \$ b_i \$ to be only 0 or 1.
...but what if we allow digits outside that range? How about also allowing the "bits" 2 and 3?
The normal representation of 18 in binary would be 10010, but since 10 is \$ 1 \times 2^1 + 0 \times 2^0 = 1 \times 2 + 0 = 2 \$,
we could also write it as 02 (\$ 0 \times 2^1 + 2 \times 2^0 = 2 \$), we could also write \$ 18 \$, in an "overflowed" binary, as 10002.
But we can also see that 10000 (\$ 16 \$) could be 02000, so \$ 18 \$ could be 02002. We can repeat this process
and get a whole list of possible "overflowed binary" encodings for our number \$ 18 \$ (which includes \$ 18 \$'s normal binary encoding):
10010
10002
02010
02002
01210
01202
01130
01122
00330
00322
Task
Given a number \$ n \$ and a maximum digit value \$ c \$, output all possible lists of digits between \$ 0 \$ and \$ c \$ (inclusive) which encode \$ n \$ in overflowed binary.
Rules
- You may assume \$ n \$ and \$ c \$ will both be integers with \$ n \ge 0 \$ and \$ c \ge 1 \$
- You may output lists with any (finite) number of leading zeroes, but you not output duplicate lists that differ only by leading zeroes;
for example, you may not output both
[0, 1, 3]and[1, 3] - You must output in a way that clearly separates digits, even when they are greater than \$ 9 \$.
For example,
[13, 2]must be distinguishable from[1, 3, 2] - You may use any reasonable I/O method
- Standard loopholes are forbidden
- This is code-golf, so the shortest code in bytes wins
Test cases
These test outputs are padded with leading zeroes such that all output lists are the same length.
n c output
--------------
0 1 [[0]]
0 5 [[0]]
1 1 [[1]]
4 7 [[0,0,4],[0,1,2],[0,2,0],[1,0,0]]
18 3 [[0,0,3,2,2],[0,0,3,3,0],[0,1,1,2,2],[0,1,1,3,0],[0,1,2,0,2],[0,1,2,1,0],[0,2,0,0,2],[0,2,0,1,0],[1,0,0,0,2],[1,0,0,1,0]]
12 12 [[0,0,0,12],[0,0,1,10],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