How many 5-digit numbers are there such that every 2 neighbouring digits differ by 3?
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.
The simplest option would be to write some code and check all 5 -digit numbers.
A slightly nicer approach is to see what happens when we vary the number of digits. Let's call these numbers 3 -diffs, and define f ( n , d ) to be the number of 3 -diffs with n digits that end with the digit d .
As an example, f ( 2 , 4 ) = 2 - these are 1 4 and 7 4 .
We have f ( 1 , d ) = 1 for d = 1 , … , 9 . Because we don't want to allow numbers that start with 0 , it's helpful to define f ( 1 , 0 ) = 0 .
We can then work out f ( n + 1 , d ) for each d as follows:
f ( n + 1 , 0 ) f ( n + 1 , 1 ) f ( n + 1 , 2 ) f ( n + 1 , 3 ) f ( n + 1 , 4 ) f ( n + 1 , 5 ) f ( n + 1 , 6 ) f ( n + 1 , 7 ) f ( n + 1 , 8 ) f ( n + 1 , 9 ) = f ( n , 3 ) = f ( n , 4 ) = f ( n , 5 ) = f ( n , 0 ) + f ( n , 6 ) = f ( n , 1 ) + f ( n , 7 ) = f ( n , 2 ) + f ( n , 8 ) = f ( n , 3 ) + f ( n , 9 ) = f ( n , 4 ) = f ( n , 5 ) = f ( n , 6 )
(essentially we're counting how many 3 -diffs with n digits we can add a d onto - this is why we had to be careful with f ( 1 , 0 ) ). It's now easy to draw up a table of these f ( n , d ) values. The sum of these when n = 5 is 4 5 .
There are various shortcuts and generalisations we can make about the function f (for example, f ( n , 1 ) = f ( n , 2 ) = f ( n , 7 ) = f ( n , 8 ) for all n ); we could even explicitly solve for the function f . But since we're only after 5 digits, a table seems a good enough approach.
I suspect there's a good combinatorial method; the problem also has some similarities with random walks.