Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #35 May 03 2019 23:12:10
%S 1,10,100,101,102,20,120,200,201,202,203,30,103,130,230,300,301,302,
%T 303,304,40,104,140,204,240,340,400,401,402,403,404,405,50,105,150,
%U 205,250,305,350,450,500,501,502,503,504,505,506,60,106,160,206,260,306,360
%N a(n) is the smallest positive number not yet in the sequence that contains both the smallest and largest digits from a(n-1); a(1)=1.
%C All terms starting with a(2)=10 must contain the digit 0.
%C From a(110)=809 onwards all terms must contain the digits 0 and 9.
%C Note that A011540 can also be defined as the sequence where a(n) is the smallest number not yet in the sequence that contains the smallest digit from a(n-1). See crossrefs.
%e a(2)=10 since 10 is the smallest positive number not yet in the sequence that contains the smallest and largest digit (i.e., 1) from a(1)=1.
%e a(6)=20 since 20 is the smallest positive number not yet in the sequence that contains the smallest and largest digits from a(5)=102.
%p N:= 1000: # for terms before the first term > N
%p A[1]:= 1:
%p S:= [$2..N]:
%p dmin:= 1: dmax:= 1:
%p found:= true:
%p for n from 2 while found do
%p found := false;
%p for i from 1 to nops(S) do
%p L:= convert(convert(S[i],base,10),set);
%p if {dmin,dmax} subset L then
%p A[n]:= S[i];
%p dmax:= max(L);
%p dmin:= min(L);
%p found:= true;
%p S:= subsop(i=NULL, S);
%p break
%p fi
%p od;
%p od:
%p convert(A,list); # _Robert Israel_, Mar 28 2019
%t Nest[Append[#, Block[{k = 2, d}, While[Nand[FreeQ[#[[All, 1]], k], SubsetQ[Set[d, IntegerDigits[k]], #[[-1, -1]] ]], k++]; {k, {Min@ d, Max@ d}}]] &, {{1, {1, 1}}}, 53][[All, 1]] (* _Michael De Vlieger_, Jan 27 2019 *)
%o (PARI) getFirstTerms(n)={my(Z=List(),A=List([1]),dd=[0,1],c,m=1);for(k=2,+oo,forvec(y=vector(k,u,[u==1,9]),listput(Z,y);for(i=1,#Z,if(m==n,return(Vec(A)));c=2;for(q=1,2,for(j=1,#Z[i],if(Z[i][j]==dd[q],c--;break)));if(!c,dd[1]=vecmin(Z[i]);dd[2]=vecmax(Z[i]);listput(A,fromdigits(Z[i]));listpop(Z,i);m++;break)),0))} \\ _R. J. Cano_, Feb 04 2019
%o (PARI) isok(k, vas, dm, dM) = {if (vecsearch(vas, k), return (0)); my(dk = Set(digits(k))); vecsearch(dk, dm) && vecsearch(dk, dM);}
%o nexta(va, vas, i) = {my(k=1, d=digits(va[i]), dm = vecmin(d), dM = vecmax(d)); while (!isok(k, vas, dm, dM), k++); k;}
%o lista(nn) = {my(va = vector(nn)); va[1] = 1; my(vas = vecsort(va,,8)); for (n=2, nn, va[n] = nexta(va, vas, n-1); vas = vecsort(va,,8);); va;} \\ _Michel Marcus_, Feb 05 2019
%Y Cf. A107353, A011540 (smallest digit only), A286890 (largest digit only), A303605.
%K nonn,base
%O 1,2
%A _Enrique Navarrete_, Jan 24 2019