[Math] Number of 6-digit pins with no consecutive number nor repeated digit

combinationscombinatoricsdiscrete mathematics

Synopsis:

The following question has been asked on a different stackexchange :

https://security.stackexchange.com/questions/219197/can-having-certain-restrictions-rules-make-passcodes-less-secure/219203#219203

I provided an answer by computing all the possible values in the subset.
I am now wondering how this result can be found mathematically.


Question:

Consider a pin enter image description here

How many pins can be chosen assuming the following rules:

  • The pin can not contains 2 consecutive numbers (ie: 112589 not ok, 131313 ok)
  • The pin does not contains 2 sequential numbers (ie: 124821 not ok, 142536 ok)
  • 9 is sequentially followed by 0

Partial Answer

The number of pins verifying the first rule is $10 * 9^5 = 590490$ , the first digit can be whatever, the following digits are chosen from a set of 9 digit (10 except the previous one)

The same number of pins verifies the second rule.

Now, I suppose that the solution is based on the sum of the number of pins verifying the first rule and the number of pins verifying the second rule, minus the number of the pins that verify both the rules.

How can the latest subset be defined ?

Best Answer

You can just consider both rules simultaneously. For each digit, there are exactly 2 digits which cannot be followed right after: itself and the sequential digit (as $9$ has $0$ as its sequential digit). Since there are only $8$ choices from the second digit onwards, we can thus compute the total number of such pins by $10(8^5)$.