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.

A358497 Replace each new digit in n with index 1, 2, ..., 9, 0 in order in which that digit appears in n, from left to right.

Original entry on oeis.org

1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12
Offset: 0

Views

Author

Gleb Ivanov, Nov 19 2022

Keywords

Comments

a(n) gives the canonical form which enumerates digits in order of their first occurrence in n, from left to right. a(n) uniquely defines the pattern of identical digits in n. - Dmytro Inosov, Jul 16 2024

Examples

			n = 10 has 2 different digits; replace first encountered digit 1 -> 1, replace second digit 0 -> 2, therefore a(10) = 12.
n = 141 has 3 digits, but only 2 different ones; replace first encountered digit 1 -> 1, replace second encountered digit 4 -> 2, therefore a(141) = 121.
		

Crossrefs

Cf. A071159, A227362, A358615 (record high values).

Programs

  • Mathematica
    A358497[k_] := With[{pI = Values@PositionIndex@IntegerDigits@k}, MapIndexed[#1 -> Mod[#2[[1]], 10] &, pI, {2}] // Flatten // SparseArray // FromDigits]; (* Dmytro Inosov, Jul 15 2024 *)
  • PARI
    a(n) = {if(n == 0, return(1)); my(d = digits(n), m = Map(), t = 0); for(i = 1, #d, if(mapisdefined(m, d[i]), d[i] = mapget(m, d[i]) , t++; if(t == 10, t = 0); mapput(m, d[i], t); d[i] = t ) ); fromdigits(d) } \\ David A. Corneth, Nov 23 2022
  • Python
    def A358497(n):
        d,s,k = dict(),str(n),1
        for i in range(len(s)):
            if d.get(s[i],0) == 0:
                d[s[i]] = str(k)
                k = (k + 1)%10
        s_t = list(s)
        for i in range(len(s)):s_t[i] = d[s[i]]
        return int(''.join(s_t))
    print([A358497(i) for i in range(100)])
    
  • Python
    def A358497(n):
        s, c, i  = str(n), {}, 49
        for d in map(ord,s):
            if d not in c:
                c[d] = i
                i += 1
        return int(s.translate(c)) # Chai Wah Wu, Jul 09 2024
    

Formula

a(a(n)) = a(n). - Dmytro Inosov, Jul 16 2024