login
A350671
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.
3
1, 11, 10, 102, 12, 21, 22, 2, 122, 20, 100, 30, 33, 3, 133, 23, 32, 123, 13, 31, 101, 14, 41, 44, 4, 144, 24, 42, 124, 104, 40, 140, 103, 105, 15, 51, 55, 5, 155, 25, 52, 125, 110, 16, 61, 66, 6, 166, 26, 62, 126, 106, 60, 160, 107, 17, 71, 77, 7, 177, 27, 72, 127, 113, 18
OFFSET
1,2
COMMENTS
Comment from Michael S. Branicky and N. J. A. Sloane, Jan 31 2022: (Start)
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.
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)
Terms computed by Claudio Meller.
EXAMPLE
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.
MATHEMATICA
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 *)
PROG
(Python)
from itertools import islice
def c(s, t): return sum(t.count(si) for si in s)
def agen(): # generator of terms
an, target, seen, mink = 1, "1", {1}, 2
while True:
yield an
k = mink
while k in seen or c(str(k), target) != 2: k += 1
an, target = k, str(k)
seen.add(an)
while mink in seen: mink += 1
print(list(islice(agen(), 81))) # Michael S. Branicky, Jan 10 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rodolfo Kurchan, Jan 10 2022
STATUS
approved