Let ( 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 . How many digits does the term a 2 0 1 8 have?
Hints:
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.
Is there a mathematical proof to why this pattern emerges?
Why didn't you use 72 as a20?
Log in to reply
a 1 9 = 1 1 1 , and a 2 0 > a 1 9 , so a 2 0 = 7 2 .
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?
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!
Why there is a 1/2 in the function?
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.
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) ≈ 8 i . Using this information, we see that 8 2 0 1 8 ≈ 2 5 2
The subsequence ( a 8 k + 2 ) for k = 3 , 4 , 5 , 6 , … is a 2 6 = 8 0 0 , a 3 4 = 8 0 0 0 , a 4 2 = 8 0 0 0 0 , a 5 0 = 8 0 0 0 0 0 , …
Notice that for each value of k , the term in the subsequence has k digits.
Solving for k in 8 k + 2 = 2 0 1 8 gives k = 2 5 2 . Therefore from the subsequence above, a 2 0 1 8 would have 2 5 2 digits.
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 |
|
1 2 |
|
1 2 3 |
|
@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.
Problem Loading...
Note Loading...
Set Loading...
Terms a 0 to a 1 9 are 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 0 , 2 2 , 3 0 , 4 1 , 5 0 , 6 1 , 7 0 , 8 1 , 9 0 , 1 1 1 .
After this, a pattern emerges: terms a 2 0 to a 2 7 are 2 0 0 , 3 1 1 , 4 0 0 , 5 1 1 , 6 0 0 , 7 1 1 , 8 0 0 , 9 1 1 ; terms a 2 8 to a 3 5 are 2 0 0 0 , 3 1 1 1 , 4 0 0 0 , 5 1 1 1 , 6 0 0 0 , 7 1 1 1 , 8 0 0 0 , 9 1 1 1 ; and so on, so that 1 more digit is added for every 8 terms.
Using 8 1 as a slope (since 1 digit is added every 8 terms), and ( 2 0 , 3 ) as a point (since a 2 0 has 3 digits), and the floor function (since the number of digits must be an integer), we can relate the the number of digits d and the n t h term by the function d = ⌊ 8 1 n + 2 1 ⌋ for n ≥ 2 0 .
Therefore, a 2 0 1 8 would have d = ⌊ 8 1 ⋅ 2 0 1 8 + 2 1 ⌋ = 2 5 2 digits.