Avoidance Sequence

Let ( a n ) (a_n) be a sequence of integers defined as a 0 = 0 ; a 1 = 1 ; a n + 1 = the next integer that shares no digits with a n . a_0 = 0; \quad a_1 = 1; \quad a_{n+1}=\text{the next integer that shares no digits with }a_n. How many digits does the term a 2018 a_{2018} have?

Hints:

  1. Here are a few more terms in the sequence: a 2 = 2 , a 3 = 3 , . . . , a 9 = 9 , a 10 = 10 , a 11 = 22 , a 12 = 30 , a 13 = 41 , . a_2=2,\ a_3=3,\ ...,\ a_9=9,\ a_{10}=10,\ a_{11}=22,\ a_{12}=30,\ a_{13}=41,\, \ldots.
  2. Try finding the pattern for the subsequence ( a 8 k + 2 ) k 3 . (a_{8k+2})_{k \geq 3}.


The answer is 252.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

5 solutions

David Vreken
Mar 3, 2018

Terms a 0 a_{0} to a 19 a_{19} are 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 22 , 30 , 41 , 50 , 61 , 70 , 81 , 90 , 111 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 22, 30, 41, 50, 61, 70, 81, 90, 111 .

After this, a pattern emerges: terms a 20 a_{20} to a 27 a_{27} are 200 , 311 , 400 , 511 , 600 , 711 , 800 , 911 200, 311, 400, 511, 600, 711, 800, 911 ; terms a 28 a_{28} to a 35 a_{35} are 2000 , 3111 , 4000 , 5111 , 6000 , 7111 , 8000 , 9111 2000, 3111, 4000, 5111, 6000, 7111, 8000, 9111 ; and so on, so that 1 1 more digit is added for every 8 8 terms.

Using 1 8 \frac{1}{8} as a slope (since 1 1 digit is added every 8 8 terms), and ( 20 , 3 ) (20, 3) as a point (since a 20 a_{20} has 3 3 digits), and the floor function (since the number of digits must be an integer), we can relate the the number of digits d d and the n t h n^{th} term by the function d = 1 8 n + 1 2 d = \lfloor \frac{1}{8}n + \frac{1}{2} \rfloor for n 20 n \geq 20 .

Therefore, a 2018 a_{2018} would have d = 1 8 2018 + 1 2 = 252 d = \lfloor \frac{1}{8} \cdot 2018 + \frac{1}{2} \rfloor = \boxed{252} digits.

Is there a mathematical proof to why this pattern emerges?

Deepak Gupta - 3 years, 2 months ago

Why didn't you use 72 as a20?

Kushagra Gupta - 3 years, 2 months ago

Log in to reply

a 19 = 111 a_{19} = 111 , and a 20 > a 19 a_{20} > a_{19} , so a 20 72 a_{20} \neq 72 .

David Vreken - 3 years, 2 months ago

Why is it not every 9 rather than 8? Which means the answer should be 2018/9 which lies between 224 and 225 making the answer 225 digits?

Michael Issac - 3 years, 2 months ago

Log in to reply

Sorry. Just saw the pattern. After a18, a digit is added every 8 numbers. This makes the solution (2018-18)/8= 250 digits plus 2 digits from a0 to a18. Therefore 252!

Michael Issac - 3 years, 2 months ago

Why there is a 1/2 in the function?

সামিন সালেক - 3 years, 1 month ago

Log in to reply

I found the linear equation using 1/8 as a slope and (20, 3) as a point, so using y = mx + b I get 3 = 1/8(20) + b, and solving for b gives b = 1/2.

David Vreken - 3 years, 1 month ago
Austin Voecks
Mar 15, 2018

Initially, it looked like this was something that could be solved through exploration, so I wrote a Python program to find solutions that matched the examples provided.

def share_digits(a, b):
    # are any of the digits in a shared by b?
    x = set(str(a))
    y = set(str(b))
    return x & y

results = [0]
i = 1
limit = 45

while i < limit:
    new = previous = results[i - 1]

    while share_digits(new, previous):
        new += 1

    results.append(new)
    print(i, new)
    i += 1

However, after running it for a couple seconds it became abundantly clear that it would take a very long time to reach 2018.

1 1
2 2
3 3
...
19 111
20 200
21 311
22 400
23 511
24 600
25 711
26 800
27 911
28 2000
29 3111
30 4000
31 5111
32 6000
33 7111
34 8000
35 9111
36 20000

But a pattern became visible after around 36 iterations. By inspecting the length of the digits compared to their position in the result, we can see that num_digits(i) i 8 \text{num\_digits(i)} \approx \frac{i}{8} . Using this information, we see that 2018 8 252 \frac{2018}{8} \approx 252

Michael Musson
Mar 16, 2018

The subsequence ( a 8 k + 2 ) (a_{8k+2}) for k = 3 , 4 , 5 , 6 , k=3, 4, 5, 6, \dots is a 26 = 800 , a 34 = 8000 , a 42 = 80000 , a 50 = 800000 , a_{26}=800,\ a_{34}=8000,\ a_{42}=80000,\ a_{50}=800000, \dots

Notice that for each value of k k , the term in the subsequence has k k digits.

Solving for k k in 8 k + 2 = 2018 8k+2 = 2018 gives k = 252 k=252 . Therefore from the subsequence above, a 2018 a_{2018} would have 252 \boxed{252} digits.

S. Saida
Mar 17, 2018

I wrote a program to solve it. You don't need to use arrays because only the first 2 digits matters, and the other digits are just the same as the second digit.

int find_digit(int start, int avoid1, int avoid2) {
  for (int dig = start; dig <= 9; ++dig) {
     if (dig != avoid1 && dig != avoid2) return dig;
   }
  return -1;
}

void main(void) {
  // Let's start from a10.
  int digits = 2;
  int first_dig = 1;
  int second_dig = 0;
  int prev_first_dig;
  int prev_second_dig;
  for (int a = 11; a <= 2018; ++a) {
    prev_first_dig = first_dig;
    prev_second_dig = second_dig;
    first_dig = find_digit(prev_first_dig + 1, prev_first_dig, prev_second_dig);
    if (first_dig < 0) {
      ++ digits;
      first_dig = find_digit(1, prev_first_dig, prev_second_dig);
    }
    second_dig = find_digit(0, prev_first_dig, prev_second_dig);
    printf("First 2 digits of a%d: %d%d, total digits: %d\n", a, first_dig, second_dig, digits);
  }
}

Output:

First 2 digits of a2018: 80, total digits: 252.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
arr_ = [i for i in range(11)]
vals = [i for i in range(10)]
next_int = ''
z = 0
k = []
term = 2018

for i in range(2019): 
    for j in range(len(str(arr_[-1]))):
        k.append(int(str(arr_[-1])[j]))
    for j in range(len(str(arr_[-1]))):
        if j > 0:
            z = min(list(set(vals).difference(set(k))))
        elif j == 0 and int(str(arr_[-1])[j]) < 9:
            z =  int(str(arr_[-1])[j]) + 1
        elif j == 0 and int(str(arr_[-1])[j]) == 9 and len(str(arr_[-1])) == 2:
            z = int('1%d' %(min(list(set(vals).difference(set(k))))))
        else:
            z = int('2%d' %(min(list(set(vals).difference(set(k))))))
        next_int += str(z)

    arr_.append(int(next_int))
    next_int = ''
    k = []

print 'Length of a_%d term is %d' % (term, len(str(arr_[term])))
print 'a_%d term is %d' %( term, arr_[term])

1
2
Length of a_2018 term is 252
a_2018 term is 800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

1
2
3
Length of a_39 term is 5
a_39 term is 51111
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 22, 30, 41, 50, 61, 70, 81, 90, 111, 200, 311, 400, 511, 600, 711, 800, 911, 2000, 3111, 4000, 5111, 6000, 7111, 8000, 9111, 20000, 31111, 40000, 51111, 60000, 71111, 80000, 91111, 200000, 311111, 400000, 511111, 600000, 711111, 800000.........]

@Michael Fitzgerald Currently, we only allow a solution to be submitted by those who answered the problem correctly, which is why you were unable to post a solution.

I have converted your comment into a solution and deleted the comments.

Calvin Lin Staff - 3 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...