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.

A358098 a(n) is the largest integer m < n such that m and n have no common digit, or -1 when such integer m does not exist.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 19, 9, 19, 19, 19, 19, 19, 19, 19, 18, 29, 29, 19, 29, 29, 29, 29, 29, 29, 28, 39, 39, 39, 29, 39, 39, 39, 39, 39, 38, 49, 49, 49, 49, 39, 49, 49, 49, 49, 48, 59, 59, 59, 59, 59, 49, 59, 59, 59, 58, 69, 69, 69, 69, 69, 69, 59, 69, 69, 68, 79
Offset: 1

Views

Author

Bernard Schott, Oct 29 2022

Keywords

Comments

Note that only when n is pandigital with 0 (A050278, A171102), such m does not exist and a(n) = -1; see examples for smallest pandigital cases.

Examples

			a(19) = 8, a(20) = 19; a(21) = 9.
a(123456789) = 0; a(1234567890) = -1.
		

Crossrefs

Cf. A358097 (similar, with smallest integer m > n).

Programs

  • Mathematica
    a[n_] := Module[{d = Complement[Range[0, 9], IntegerDigits[n]], m = n - 1}, If[d == {} || d == {0}, -1, While[m >= 0 && ! AllTrue[IntegerDigits[m], MemberQ[d, #] &], m--]; m]]; Array[a, 100] (* Amiram Eldar, Oct 29 2022 *)
  • PARI
    a(n) = my(d=Set(digits(n))); forstep (m=n-1, 0, -1, if (!#setintersect(d, Set(digits(m))), return(m))); return(-1); \\ Michel Marcus, Oct 30 2022
  • Python
    from itertools import product
    def a(n):
        s = str(n)
        r = sorted(set("1234567890") - set(s), reverse=True)
        if len(r) == 0: return -1
        if r == ["0"]: return 0
        for d in range(len(s), 0, -1):
            for p in product(r, repeat=d):
                m = int("".join(p))
                if m < n: return m
    print([a(n) for n in range(1, 81)]) # Michael S. Branicky, Oct 29 2022
    

Formula

a(10^n) = 10^n - 1 for n >= 0.
a(A050289(n))=0.