How many 10-digit sequence are there?

Find the number of 10-digit sequences where the difference between any two consecutive digits is 1, using only the digits 1, 2, 3, and 4.

Examples of such 10-digit sequences are 1234321232 and 2121212121.


Bonus: Let T ( n ) T(n) be the number of such n n -digit sequences. What is lim n T ( n + 1 ) T ( n ) ? \lim_{n \to \infty} \frac{T(n+1)}{T(n)}?


The answer is 288.

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.

7 solutions

Chan Lye Lee
Apr 5, 2018

Let T ( n ) T(n) be the number of such n n -digit sequence.

Let A ( n ) A(n) be the number of such n n -digit sequence that end in either 1 or 4.

Let B ( n ) B(n) be the number of such n n -digit sequence that end in either 2 or 3.

Now T ( n ) = A ( n ) + B ( n ) T(n)=A(n)+B(n) .

Note that A ( n + 1 ) = B ( n ) A(n+1)=B(n) and B ( n + 1 ) = B ( n ) + A ( n ) = B ( n ) + B ( n 1 ) B(n+1)=B(n)+A(n)=B(n)+B(n-1) . Since A ( 1 ) = 2 , B ( 1 ) = 2 A(1)=2, B(1)=2 , we can construct the following table, using the mentioned recursive relation, and obtain the answer.

For the bonus question: lim n T ( n + 1 ) T ( n ) = lim n A ( n + 1 ) + B ( n + 1 ) A ( n ) + B ( n ) = lim n B ( n ) + B ( n + 1 ) B ( n 1 ) + B ( n ) = lim n B ( n + 2 ) B ( n + 1 ) = . . . = ϕ 1.61803 \displaystyle \lim_{n \to \infty} \frac{T(n+1)}{T(n)} = \lim_{n \to \infty} \frac{A(n+1)+B(n+1)}{A(n)+B(n)} = \lim_{n \to \infty} \frac{B(n)+B(n+1)}{B(n-1)+B(n)} = \lim_{n \to \infty} \frac{B(n+2)}{B(n+1)} =...= \phi \approx 1.61803

The meat of the solution is hidden in "Note that".

Richard Desper - 3 years, 1 month ago

Nice solution, exactly what i would have written. Is this generalizable using m different "digits" on each digit space (instead of just 4)? I will try to solve that. :)

Jakob Andersen - 3 years, 1 month ago

Both A and B are slight alterations of the Fibonacci sequence, where A(n)=2F(n) and B(n)=2F(n+1), hence T(n) = 2F(n+2)

Mikhaella Layos - 3 years, 1 month ago

Log in to reply

Exactly what i want to write

saad belkhadir mellas - 3 years, 1 month ago
Henri X
Apr 16, 2018

You can also figure this using a tree diagram. For the numbers starting 1 and 4, there is only one possibility for the result. You will find out for every digit, it goes in a Fibonacci sequence, so for the case of the first digit being 1 and 4, the sequence goes 1 1 2 3 5 8 13 21 34 55, 55 is the number of possible outcomes for the number starting with 1, and 55 is the number of possible outcomes for the number starting with 4. For 2 and 3, since the number of options for the second number is 2, we skip the first number of the Fibonacci sequence, thus leaving us with the 11th number of the Fibonacci sequence, 89 for the number of possibilities for 2, and another 89 possibilities with 3.

Therefore, the number of results is (55+89)*2=288

I found it like that too ! :D

lol lol - 3 years, 1 month ago

Log in to reply

hehe great minds thik alike B)

Henri X - 3 years, 1 month ago

I did that too

Andrew Kerr - 3 years, 1 month ago

Sir, Where is it written that the number should start with 1 0r 4 or end with 1 or 4. Why can't we fix first place by 4 possibilities (1,2,3,4) and so each next term will have 2 possibility (consecutively). 4*2^9=2048. Plz do tell me my mistakes

Satyam singh - 3 years, 1 month ago

Log in to reply

If we start with 1 then first digit can be written in 1 way, second digit in 1 way , third digit in 2 ways, fourth digit in 3 ways, fifth digit in 5 ways and so on. Now if we can observe that the pattern follows Fibonacci sequence hence the 10th digit can be written in 55 ways. The same is the case for 4. The case of 2 or 3 is nothing but the same sequence as 1 or 4 starting from 2nd digit of that sequence and adding one more digit at the end which can be written in 89 ways. Hence 2 * (55 + 89) = 288

Aditya Nistala - 3 years ago
Filip Kramaric
Apr 16, 2018
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import itertools
def testing(list1):
    for x, y in zip(list1, list1[1:]):
        if abs(x-y) != 1 :
            return False
    return True
count = 0
x = list(itertools.product(range(1,5), repeat=10))
for n in range(len(x)):
    if testing(list(x[n])) == True:
        count +=1
print(count)

  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
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#1      1212121212
#2      1212121232
#3      1212121234
#4      1212123212
#5      1212123232
#6      1212123234
#7      1212123432
#8      1212123434
#9      1212321212
#10     1212321232
#11     1212321234
#12     1212323212
#13     1212323232
#14     1212323234
#15     1212323432
#16     1212323434
#17     1212343212
#18     1212343232
#19     1212343234
#20     1212343432
#21     1212343434
#22     1232121212
#23     1232121232
#24     1232121234
#25     1232123212
#26     1232123232
#27     1232123234
#28     1232123432
#29     1232123434
#30     1232321212
#31     1232321232
#32     1232321234
#33     1232323212
#34     1232323232
#35     1232323234
#36     1232323432
#37     1232323434
#38     1232343212
#39     1232343232
#40     1232343234
#41     1232343432
#42     1232343434
#43     1234321212
#44     1234321232
#45     1234321234
#46     1234323212
#47     1234323232
#48     1234323234
#49     1234323432
#50     1234323434
#51     1234343212
#52     1234343232
#53     1234343234
#54     1234343432
#55     1234343434
#56     2121212121
#57     2121212123
#58     2121212321
#59     2121212323
#60     2121212343
#61     2121232121
#62     2121232123
#63     2121232321
#64     2121232323
#65     2121232343
#66     2121234321
#67     2121234323
#68     2121234343
#69     2123212121
#70     2123212123
#71     2123212321
#72     2123212323
#73     2123212343
#74     2123232121
#75     2123232123
#76     2123232321
#77     2123232323
#78     2123232343
#79     2123234321
#80     2123234323
#81     2123234343
#82     2123432121
#83     2123432123
#84     2123432321
#85     2123432323
#86     2123432343
#87     2123434321
#88     2123434323
#89     2123434343
#90     2321212121
#91     2321212123
#92     2321212321
#93     2321212323
#94     2321212343
#95     2321232121
#96     2321232123
#97     2321232321
#98     2321232323
#99     2321232343
#100    2321234321
#101    2321234323
#102    2321234343
#103    2323212121
#104    2323212123
#105    2323212321
#106    2323212323
#107    2323212343
#108    2323232121
#109    2323232123
#110    2323232321
#111    2323232323
#112    2323232343
#113    2323234321
#114    2323234323
#115    2323234343
#116    2323432121
#117    2323432123
#118    2323432321
#119    2323432323
#120    2323432343
#121    2323434321
#122    2323434323
#123    2323434343
#124    2343212121
#125    2343212123
#126    2343212321
#127    2343212323
#128    2343212343
#129    2343232121
#130    2343232123
#131    2343232321
#132    2343232323
#133    2343232343
#134    2343234321
#135    2343234323
#136    2343234343
#137    2343432121
#138    2343432123
#139    2343432321
#140    2343432323
#141    2343432343
#142    2343434321
#143    2343434323
#144    2343434343
#145    3212121212
#146    3212121232
#147    3212121234
#148    3212123212
#149    3212123232
#150    3212123234
#151    3212123432
#152    3212123434
#153    3212321212
#154    3212321232
#155    3212321234
#156    3212323212
#157    3212323232
#158    3212323234
#159    3212323432
#160    3212323434
#161    3212343212
#162    3212343232
#163    3212343234
#164    3212343432
#165    3212343434
#166    3232121212
#167    3232121232
#168    3232121234
#169    3232123212
#170    3232123232
#171    3232123234
#172    3232123432
#173    3232123434
#174    3232321212
#175    3232321232
#176    3232321234
#177    3232323212
#178    3232323232
#179    3232323234
#180    3232323432
#181    3232323434
#182    3232343212
#183    3232343232
#184    3232343234
#185    3232343432
#186    3232343434
#187    3234321212
#188    3234321232
#189    3234321234
#190    3234323212
#191    3234323232
#192    3234323234
#193    3234323432
#194    3234323434
#195    3234343212
#196    3234343232
#197    3234343234
#198    3234343432
#199    3234343434
#200    3432121212
#201    3432121232
#202    3432121234
#203    3432123212
#204    3432123232
#205    3432123234
#206    3432123432
#207    3432123434
#208    3432321212
#209    3432321232
#210    3432321234
#211    3432323212
#212    3432323232
#213    3432323234
#214    3432323432
#215    3432323434
#216    3432343212
#217    3432343232
#218    3432343234
#219    3432343432
#220    3432343434
#221    3434321212
#222    3434321232
#223    3434321234
#224    3434323212
#225    3434323232
#226    3434323234
#227    3434323432
#228    3434323434
#229    3434343212
#230    3434343232
#231    3434343234
#232    3434343432
#233    3434343434
#234    4321212121
#235    4321212123
#236    4321212321
#237    4321212323
#238    4321212343
#239    4321232121
#240    4321232123
#241    4321232321
#242    4321232323
#243    4321232343
#244    4321234321
#245    4321234323
#246    4321234343
#247    4323212121
#248    4323212123
#249    4323212321
#250    4323212323
#251    4323212343
#252    4323232121
#253    4323232123
#254    4323232321
#255    4323232323
#256    4323232343
#257    4323234321
#258    4323234323
#259    4323234343
#260    4323432121
#261    4323432123
#262    4323432321
#263    4323432323
#264    4323432343
#265    4323434321
#266    4323434323
#267    4323434343
#268    4343212121
#269    4343212123
#270    4343212321
#271    4343212323
#272    4343212343
#273    4343232121
#274    4343232123
#275    4343232321
#276    4343232323
#277    4343232343
#278    4343234321
#279    4343234323
#280    4343234343
#281    4343432121
#282    4343432123
#283    4343432321
#284    4343432323
#285    4343432343
#286    4343434321
#287    4343434323
#288    4343434343

Michael Fitzgerald - 3 years, 1 month ago

Log in to reply

I need to learn python, there is no excuse for a mathemtician not to know some programming..

M. Zeidan - 3 years, 1 month ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# https://brilliant.org/weekly-problems/2018-04-16/advanced/?p=4

from itertools import product

def match(l):
    y = [abs(j-i) for i, j in zip(l[:-1], l[1:])]
    sum_diff = sum(y)
    if sum_diff != numbers-1 or max(y) != 1:
        return False
    print '#%d\t%s' %(counter,''.join(str(e) for e in l))  
    return True

counter = 1
numbers = 10
range_ = 4
vals = list(product(range(1,range_+1), repeat=numbers))

for i in range(len(vals)):
    if match(list(vals[i])):
        counter +=1

Michael Fitzgerald - 3 years, 1 month ago

 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
# https://brilliant.org/weekly-problems/2018-04-16/advanced/?p=4

from itertools import product
def match(l):
    y = [abs(j-i) for i, j in zip(l[:-1], l[1:])]
    sum_diff = sum(y)
    if sum_diff != numbers-1 or max(y) != 1:
        return False
    #print '#%d\t%s' %(counter,''.join(str(e) for e in l))  
    return True

range_ = 4  # how many unique consecutive numbers

Fib = []
for numbers in range(range_,14):
    counter = 1
    vals = list(product(range(1,range_+1), repeat=numbers))
    for i in range(len(vals)):
        if match(list(vals[i])):
            counter +=1
    print '%d digit sequence: %d sequences' %( numbers, counter-1)
    Fib.append(counter-1)
    counter = 1

y = [float(j)/i for i, j in zip(Fib[:-1], Fib[1:])]
print y
print 'Limit as sequence tends to oo: %0.6f' % y[len(y)]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
4 digit sequence: 16 sequences
5 digit sequence: 26 sequences
6 digit sequence: 42 sequences
7 digit sequence: 68 sequences
8 digit sequence: 110 sequences
9 digit sequence: 178 sequences
10 digit sequence: 288 sequences
11 digit sequence: 466 sequences
12 digit sequence: 754 sequences
13 digit sequence: 1220 sequences
[1.625, 1.6153846153846154, 1.619047619047619, 1.6176470588235294, 1.6181818181818182, 1.6179775280898876, 1.6180555555555556, 1.6180257510729614]
Limit as sequence tends to oo: 1.618037

Michael Fitzgerald - 3 years, 1 month ago

It looks like Python is popular among users of this site. Someone has even made a Python script to brute force any problem on this site.

https://5f3759df.wordpress.com/2018/02/21/extracting-answers-to-problems-from-brilliant-org/

Binky Mh
Apr 18, 2018

We can work out the number of sequences ending with a specific digit by adding together the number of sequences up to the previous number which ends with a number adjacent to the desired number.

For example, by using the tree diagram below (considering only the sequences starting with a 1), we can see that the number of 6-digit sequences ending in 2 ( 5 ) (5) is equal to the number of 5-digit sequences ending in 1 ( 2 ) (2) added to the number of sequences ending in 3 ( 3 ) (3) : This is applicable down to just 2-digit sequences: the number of 2-digit sequences ending in 3 ( 2 ) (2) is equal to the number of 1-digit sequences ending in either 2 ( 1 ) (1) , or 4 ( 1 ) (1) . In this case, these two sequences are 2 , 3 2,3 and 4 , 3 4,3 respectively.

With this information, starting with the 4 possible 1-digit sequences, we can work out the number of sequences of successive lengths ending in each digit: And now we can work out the total number of 10-digit sequences using 55 + 89 + 89 + 55 = 288 55+89+89+55=\boxed{288}

For the bonus question: with the table above, we can see the Fibonacci sequence emerging as the length of the sequence increases. Because the ratio between successive numbers in the Fibonaccio sequence tends towards the golden ratio ( ϕ ) (\phi) , we can see that, as the above sequence increases in length:

T ( n + 1 ) 1 + T ( n + 1 ) 2 + T ( n + 1 ) 3 + T ( n + 1 ) 4 = ϕ T ( n ) 1 + ϕ T ( n ) 2 + ϕ T ( n ) 3 + ϕ T ( n ) 4 T(n+1)_1+T(n+1)_2+T(n+1)_3+T(n+1)_4=\phi T(n)_1+\phi T(n)_2+\phi T(n)_3+\phi T(n)_4

T ( n + 1 ) 1 + T ( n + 1 ) 2 + T ( n + 1 ) 3 + T ( n + 1 ) 4 = ϕ ( T ( n ) 1 + T ( n ) 2 + T ( n ) 3 + T ( n ) 4 ) T(n+1)_1+T(n+1)_2+T(n+1)_3+T(n+1)_4=\phi (T(n)_1+T(n)_2+T(n)_3+T(n)_4)

T ( n + 1 ) = ϕ T ( n ) T(n+1)=\phi T(n)

T ( n + 1 ) T ( n ) = ϕ 1.618 \frac{T(n+1)}{T(n)}=\phi \approx 1.618

David Vreken
Apr 17, 2018

The 1 1 -digit possibilities are 1 1 , 2 2 , 3 3 , and 4 4 ; for a total of 4 4 different sequences.

For 2 2 -digit possibilities, the first digit can be 1 1 , 2 2 , 3 3 , or 4 4 . If the first digit is 1 1 , then the second digit must be 2 2 . If the first digit is 2 2 , the the second digit must be 1 1 or 3 3 . If the first digit is 3 3 , then the second digit must be 2 2 or 4 4 . And if the first digit is 4 4 , then the second digit must be 3 3 . The possible sequences are 12 12 , 21 21 , 23 23 , 32 32 , 34 34 , and 43 43 - 1 1 starting with 1 1 , 2 2 starting with 2 2 , 2 2 starting with 3 3 , and 1 1 starting with 4 4 - for a total of 1 + 2 + 2 + 1 = 6 1 + 2 + 2 + 1 = 6 different sequences for 2 2 digits.

For 3-digit possibilities, the first digit can be 1 1 , 2 2 , 3 3 , or 4 4 . If the first digit is 1 1 , then the second digit must be 2 2 , and from above we know that there are 2 2 2 2 -digit possibilities that start with 2 2 , so there are 2 2 3 3 -digit possibilities that start with 1 1 . If the first digit is 2 2 , then the second digit must be 1 1 or 3 3 , and from above we know that there is 1 1 2 2 -digit possibility that starts with 1 1 and 2 2 2 2 -digit possibilities that start with 3 3 , for a total of 1 + 2 = 3 1 + 2 = 3 3 3 -digit possibilities that start with 2 2 . If the first digit is 3 3 , then the second digit must be 2 2 or 4 4 , and from above we know that there are 2 2 2 2 -digit possibilities that start with 2 2 and 1 1 2 2 -digit possibility that starts with 4 4 , for a total of 2 + 1 = 3 2 + 1 = 3 3 3 -digit possibilities that start with 2 2 . If the first digit is 4 4 , then the second digit must be 3 3 , and from above we know that there are 2 2 2 2 -digit possibilities that start with 3 3 , so there are 2 2 3 3 -digit possibilities that start with 4 4 . There are then a total of 2 + 3 + 3 + 2 = 10 2 + 3 + 3 + 2 = 10 different sequences for 3 3 digits.

Now we can see a recursive pattern. Let a n a_n be the number of n n -digit possibilities that start with 1 1 or 4 4 , b n b_n be the number of n n -digit possibilities that start with 2 2 or 3 3 , and t n t_n be the total number of n n -digit possibilities. Then using the above arguments, a n = b n 1 a_n = b_{n - 1} , b n = a n 1 + b n 1 b_n = a_{n - 1} + b_{n - 1} , and t n = 2 ( a n + b n ) t_n = 2(a_n + b_n) . Then substituting a n = b n 1 a_n = b_{n - 1} and b n = a n 1 + b n 1 b_n = a_{n - 1} + b_{n - 1} , we have t n = 2 ( b n 1 + a n 1 + b n 1 ) t_n = 2(b_{n - 1} + a_{n - 1} + b_{n - 1}) , and substituting b n 1 = a n 2 + b n 2 b_{n - 1} = a_{n - 2} + b_{n - 2} , we have t n = 2 ( a n 2 + b n 2 + a n 1 + b n 1 ) t_n = 2(a_{n - 2} + b_{n - 2} + a_{n - 1} + b_{n - 1}) , and since t n 1 = 2 ( a n 1 + b n 1 ) t_{n - 1} = 2(a_{n - 1} + b_{n - 1}) and t n 2 = 2 ( a n 2 + b n 2 ) t_{n - 2} = 2(a_{n - 2} + b_{n - 2}) , we have t n = t n 2 + t n 1 t_n = t_{n - 2} + t_{n - 1} .

From above we know that t 1 = 4 t_1 = 4 and t 2 = 6 t_2 = 6 , and so using t n = t n 2 + t n 1 t_n = t_{n - 2} + t_{n - 1} we can find the first 10 10 terms of the sequence to be 4 4 , 6 6 , 10 10 , 16 16 , 26 26 , 42 42 , 68 68 , 110 110 , 178 178 , and 288 288 , which means t 10 = 288 t_{10} = \boxed{288} .

Bonus: Since t n = t n 2 + t n 1 t_n = t_{n - 2} + t_{n - 1} , it has the same recursive pattern as the Fibonacci sequence, and so lim n t n + 1 t n = ϕ 1.618 \lim_{n \to \infty} \frac{t_{n + 1}}{t_n} = \phi \approx 1.618 .

Luis Ramírez
Apr 22, 2018

C#

using System;

namespace ConsoleApp1
{
    class Program
    {
        static int Count = 0;
        static long Max = (long)Math.Pow(10,9);

        static void Expand(ref long _value)
        {   if (_value > Max)
                Console.WriteLine($"[{++Count}]\t{_value}");    // branch finished
            else
            {   long _tmp;
                short _lastDigit = (short)(_value % 10);
                long _root = 10 * _value + _lastDigit;
                if (_lastDigit > 1) { _tmp = _root - 1; Expand(ref _tmp); }
                if (_lastDigit < 4) { _tmp = _root + 1; Expand(ref _tmp); }
            }
        }


        static void Main(string[] args)
        {   for(long k = 1; k<=4; k++) Expand(ref k);
            Console.WriteLine($"Count: {Count}");
        }
    }
}
Alex Burgess
Apr 19, 2018

Noting that any number must go even, odd, even, or vise versa. We can treat 1 and 4 as end points, E, and 2 and 3 as middle points, M. (Where 2 E's cannot be next to each other). (Note we are now counting precisely half of total, as we can choose the first digit to be odd or even.)

Let F(n) be the number of combinations of E and M. For n>2,

F(n)= (first digit E, 2nd digit M) F(n-2) + (first digit M) F(n-1)

F(1)=2 (E, M)

F(2)=3 (EM, ME, MM)

We can deduce that F(n) = (n+2)th Fibonacci number, f(n+2). So F(10)=144. So T(10)=288.


Extra: lim(n -> infinity) T(n+1)/T(n) = lim(n -> infinity) f(n+3) / f(n+2) = phi

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...