%I #35 Feb 01 2022 00:32:03
%S 1,11,10,102,12,21,22,2,122,20,100,30,33,3,133,23,32,123,13,31,101,14,
%T 41,44,4,144,24,42,124,104,40,140,103,105,15,51,55,5,155,25,52,125,
%U 110,16,61,66,6,166,26,62,126,106,60,160,107,17,71,77,7,177,27,72,127,113,18
%N a(n) is the smallest number not yet in the sequence that has two digits in common with a(n-1), starting with a(1) = 1.
%C Comment from _Michael S. Branicky_ and _N. J. A. Sloane_, Jan 31 2022: (Start)
%C The crux is the definition of "x has two digits in common with y". Take each digit d of x in turn, reading from left to right, and see how many times d appears in y. The sum of all these counts must be 2. E.g., x = 122 has two digits in common with 2 because the first 1 has zero matches, the first 2 has one match, and the second 2 has one match. Again, x = 110 has three digits in common with 103 because the first 1 has one match, the second 1 has one match, and the zero has one match.
%C In general, if x has decimal expansion x_1...x_e, and y has decimal expansion y_1...y_f, and delta(u,v) = 1 if u=v, 0 otherwise, then the number of digits in common between x and y is Sum_{i=1..e} Sum_{j=1..f} delta(x_i, y_j). (End)
%C Terms computed by _Claudio Meller_.
%e a(2) = 11 because it is the smallest number that has exactly two digits in common with a(1) = 1; similarly, a(3) = 10 because it has two digits in common with a(2) = 11 and a(4) = 102 because it is the smallest number that is not already in the sequence that has exactly two digits in common with a(3) = 10.
%t a[1]=1;a[n_]:=a[n]=(k=1;While[MemberQ[Array[a,n-1],k]||Total[Count[IntegerDigits@a[n-1],#]&/@IntegerDigits@k]!=2,k++];k);Array[a,65] (* _Giorgos Kalogeropoulos_, Jan 12 2022 *)
%o (Python)
%o from itertools import islice
%o def c(s, t): return sum(t.count(si) for si in s)
%o def agen(): # generator of terms
%o an, target, seen, mink = 1, "1", {1}, 2
%o while True:
%o yield an
%o k = mink
%o while k in seen or c(str(k), target) != 2: k += 1
%o an, target = k, str(k)
%o seen.add(an)
%o while mink in seen: mink += 1
%o print(list(islice(agen(), 81))) # _Michael S. Branicky_, Jan 10 2022
%Y Cf. A350444, A350445, A351059.
%K nonn,base
%O 1,2
%A _Rodolfo Kurchan_, Jan 10 2022
|