%I #31 Sep 14 2022 10:54:08
%S 1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,11,21,23,24,25,26,27,
%T 28,29,30,22,31,32,34,35,36,37,38,39,40,33,41,42,43,45,46,47,48,49,50,
%U 44,51,52,53,54,56,57,58,59,60,55,61,62,63,64,65,67,68
%N a(n) is the least positive integer not occurring earlier in the sequence that contains at least one digit not in a(n-1); a(1)=1.
%C The sequence is finite. 1023456789 should be the last number in the sequence, although many smaller numbers should fail to appear. How many terms are in the complete sequence?
%C The last term is a(1023445778) = 1023456789, the least missing number is 1000000010. - _Rémy Sigrist_, Jun 03 2022
%C At that point, the least missing numbers containing the digits 2..9 are 1020001000, 1023001300, 1023401000, 1023450200, 1023456024, 1023456710, 1023456781, 1023456789, resp. - _Michael S. Branicky_, Aug 26 2022
%H Sergio Pimentel, <a href="/A353888/b353888.txt">Table of n, a(n) for n = 1..10000</a>
%H Rémy Sigrist, <a href="/A353888/a353888.txt">C++ program</a>
%e a(11)=12 since a(10)=10 and 12 is the smallest number not occurring earlier in the sequence that contains a digit (2) that is not in 10.
%o (PARI) isok(k, prev) = {my(d=digits(k)); for (i=1, #d, if (!vecsearch(prev, d[i]), return(1));); return(0);}
%o find(va, n) = {my(k=1, prev=Set(digits(va[n-1]))); while (vecsearch(Set(va), k) || !isok(k, prev), k++); k;}
%o lista(nn) = {my(va = vector(nn)); va[1] = 1; for (n=2, nn, va[n] = find(va, n);); va;} \\ _Michel Marcus_, May 11 2022
%o (C++) See Links section.
%o (Python)
%o from itertools import count, islice
%o def agen(): # generator of terms
%o an, aset, mu, mink = 0, set(), [10, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1
%o while set(str(an)) != set("0123456789"):
%o notin = set("0123456789") - set(str(an))
%o an = min(mu[i] for i in range(10) if str(i) in notin)
%o yield an; aset.add(an)
%o for i in range(10): # update min unused containing digit i
%o while mu[i] in aset or str(i) not in str(mu[i]): mu[i] += 1
%o for k in range(mink, min(mu)): aset.discard(k)
%o mink = min(mu)
%o print(list(islice(agen(), 67))) # _Michael S. Branicky_, Aug 26 2022
%Y Cf. A184992, A162501, A130571, A107353.
%K nonn,base,fini
%O 1,2
%A _Sergio Pimentel_, May 09 2022