%I #17 Feb 04 2020 14:56:04
%S 0,1,2,3,4,5,6,7,8,9,11,1,1,1,20,1,22,3,4,25,6,27,8,29,3,33,3,3,40,1,
%T 42,3,44,5,6,47,8,49,5,5,55,5,60,1,62,3,64,5,66,7,8,69,7,7,7,77,80,1,
%U 82,3,84,5,86,7,88,9,9,9,9,9,99,100,1,2,103,4,105
%N Consider integers k=0,1,2,... as strings. Compare each digit in the string, in left-to-right order, with the contents of a bag (multiset) of digits, which is initially empty. If digit d is in the bag delete d from both the string and the bag. What remains of any nonempty string is appended to the sequence and its digits are added to the bag.
%H Rémy Sigrist, <a href="/A330430/b330430.txt">Table of n, a(n) for n = 1..10000</a>
%e 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}.
%e 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}.
%e 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}.
%o (Python)
%o seq = []
%o bag = ""
%o for k in range(1000):
%o m = str(k)
%o for digit in m:
%o if digit in bag:
%o mndx = m.index(digit)
%o m = m[:mndx] + m[mndx+1:]
%o bndx = bag.index(digit)
%o bag = bag[:bndx] + bag[bndx+1:]
%o if m:
%o seq.append(int(m))
%o bag = bag + m
%o print(seq)
%o (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
%K nonn,easy,base
%O 1,3
%A _J. Stauduhar_, Dec 14 2019
|