OFFSET
1,3
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10000
EXAMPLE
Beginning with k=0, the bag is initially empty and 0 matches nothing in the bag, so the sequence is extended and 0 is added to the bag. Likewise, for k=1-9, none of these digits match anything in the bag, resulting in the sequence [0,1,2,3,4,5,6,7,8,9] and a bag that contains {0,1,2,3,4,5,6,7,8,9}.
With k=10, Both the 1 and the 0 in k are matched with the 1 and the 0 in the bag and cancel out. This leaves an empty string, so the sequence is not extended, and the bag now contains {2,3,4,5,6,7,8,9}.
With k=11, neither digit cancels out, since there are no ones in the bag, so the sequence is extended, [0,1,2,3,4,5,6,7,8,9,11], and the bag contains {1,1,2,3,4,5,6,7,8,9}.
PROG
(Python)
seq = []
bag = ""
for k in range(1000):
m = str(k)
for digit in m:
if digit in bag:
mndx = m.index(digit)
m = m[:mndx] + m[mndx+1:]
bndx = bag.index(digit)
bag = bag[:bndx] + bag[bndx+1:]
if m:
seq.append(int(m))
bag = bag + m
print(seq)
(PARI) { my (b=vector(base=10), n=0); for (k=0, 105, d = if (k, digits(k, base), [0]); t = []; for (i=1, #d, if (b[1+d[i]], b[1+d[i]]--, t=concat(t, d[i]); ); ); if (#t, print1 (fromdigits(t, base)", "); for (j=1, #t, b[1+t[j]]++))) } \\ Rémy Sigrist, Dec 15 2019
CROSSREFS
KEYWORD
nonn,easy,base
AUTHOR
J. Stauduhar, Dec 14 2019
STATUS
approved