How many code with no two digits side by side are same

combinatorics

A code consists of 5 digit numbers arranged from integers $0, 1, 2, …, 9$. How many code with no two digits side by side are same?

I have tried to answer it as below.

First digit can filled by $0, 1, …,9$ so it have $10$ options.

Second digit can filled by $0, 1, …,9$ except the digit used in first digit, so it have $9$ options.

Third digit can filled by $0, 1, …,9$ except the digit used in second digit, so it have $9$ options.

Fourth digit can filled by $0, 1, …,9$ except the digit used in third digit, so it have $9$ options.

Fifth digit can filled by $0, 1, …,9$ except the digit used in fourth digit, so it have $9$ options.

So, the number of code is
$$10\times 9^4.$$
I'm not sure with my answer. Is it right answer? If my answer is wrong, what the hint to be used for answer this problem?

Best Answer

You are correct.

If you have doubt, a generally good idea (esp. in combinatorics) is to try smaller examples. E.g. length-$3$ codes using just letters A,B,C. By your logic you should have $3 \times 2 \times 2 = 12$ such codes (out of $27$ possible). This is easy to check by hand:

AAA, AAB, AAC, ABA, ABB, ABC, ACA, ACB, ACC,

BAA, BAB, BAC, BBA, BBB, BBC, BCA, BCB, BCC,

CAA, CAB, CAC, CBA, CBB, CBC, CCA, CCB, CCC.