• + 1 comment

    HINT: use a recurrence based on the last 4 digits of the number. In order to compute the number of solutions of length n ending in ABCD, you can get it based on the number of solutions of length n-1 ending in XABC, for each X = 0 to 9.

    The number of valid 4-digit states is way less than 10,000, I think it was 415.