cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A330430 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.

Original entry on oeis.org

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, 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, 82, 3, 84, 5, 86, 7, 88, 9, 9, 9, 9, 9, 99, 100, 1, 2, 103, 4, 105
Offset: 1

Views

Author

J. Stauduhar, Dec 14 2019

Keywords

Examples

			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}.
		

Programs

  • 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
  • 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)