A323708 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.
1, 10, 100, 101, 102, 20, 120, 200, 201, 202, 203, 30, 103, 130, 230, 300, 301, 302, 303, 304, 40, 104, 140, 204, 240, 340, 400, 401, 402, 403, 404, 405, 50, 105, 150, 205, 250, 305, 350, 450, 500, 501, 502, 503, 504, 505, 506, 60, 106, 160, 206, 260, 306, 360
Offset: 1
Examples
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. 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.
Programs
-
Maple
N:= 1000: # for terms before the first term > N A[1]:= 1: S:= [$2..N]: dmin:= 1: dmax:= 1: found:= true: for n from 2 while found do found := false; for i from 1 to nops(S) do L:= convert(convert(S[i],base,10),set); if {dmin,dmax} subset L then A[n]:= S[i]; dmax:= max(L); dmin:= min(L); found:= true; S:= subsop(i=NULL, S); break fi od; od: convert(A,list); # Robert Israel, Mar 28 2019
-
Mathematica
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 *)
-
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
-
PARI
isok(k, vas, dm, dM) = {if (vecsearch(vas, k), return (0)); my(dk = Set(digits(k))); vecsearch(dk, dm) && vecsearch(dk, dM);} 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;} 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
Comments