login
a(n) is the smallest integer m > n such that m and n have no common digit, or -1 when such integer m does not exist.
3

%I #29 Jul 03 2024 01:49:58

%S 1,2,3,4,5,6,7,8,9,10,22,20,30,20,20,20,20,20,20,20,31,30,30,40,30,30,

%T 30,30,30,30,41,40,40,40,50,40,40,40,40,40,51,50,50,50,50,60,50,50,50,

%U 50,61,60,60,60,60,60,70,60,60,60,71,70,70,70,70,70,70,80,70,70,81,80,80,80,80

%N a(n) is the smallest integer m > n such that m and n have no common digit, or -1 when such integer m does not exist.

%C When n is pandigital with or without 0 (A050278, A050289, A171102), m does not exist, so a(n) = -1; see examples for smallest pandigital cases.

%H Michel Marcus, <a href="/A358097/b358097.txt">Table of n, a(n) for n = 0..10000</a>

%F a(10^n-k) = 10^n when n >= 2 and 1 <= k <= 8.

%F a(10^n) = 2 * A002275(n+1), when n >= 1.

%e a(10) = 22; a(11) = 20; a(12) = 30.

%e a(123456789) = -1; a(1234567890) = -1.

%t a[n_] := Module[{d = Complement[Range[0, 9], IntegerDigits[n]], m = n + 1}, If[d == {} || d == {0}, -1, While[! AllTrue[IntegerDigits[m], MemberQ[d, #] &], m++]; m]]; Array[a, 100, 0] (* _Amiram Eldar_, Oct 29 2022 *)

%o (PARI) isfull(d) = my(dd=setminus([0..9], d)); (dd==[]) || (dd==[0]);

%o a(n) = my(d=Set(digits(n))); if (isfull(d), -1, my(k=n+1); while (#setintersect(Set(digits(k)), d), k++); k); \\ _Michel Marcus_, Oct 29 2022

%o (Python)

%o from itertools import count, product

%o def a(n):

%o s = str(n)

%o r = sorted(set("1234567890") - set(s))

%o if len(r) == 0 or r == ["0"]: return -1

%o for d in count(len(s)):

%o for p in product(r, repeat=d):

%o m = int("".join(p))

%o if m > n: return m

%o print([a(n) for n in range(75)]) # _Michael S. Branicky_, Oct 29 2022

%Y Cf. A002275, A050278, A050289, A171102.

%Y Cf. A030283 (trajectory starting 0).

%Y Cf. A358098 (similar, with largest integer m < n).

%K nonn,base,easy

%O 0,2

%A _Bernard Schott_, Oct 29 2022