A step number is a positive integer whose adjacent decimal digits differ by exactly . For example, and are step numbers, while is not: its first two numerical digits have difference zero. Repetition is allowed; only neighboring differences are constrained.
The numerical digits form a walk on the path graph , starting at a nonzero digit. From a last digit , the possible extensions are within the range . At endpoints there is only one extension.
For digit dynamic programming, record the last digit and a bit mask encoding the set of digits already visited. Appending updates the visited set by set union with . Here pandigital means that every decimal digit appears at least once; repetitions are allowed. Accept only final states whose visited set contains all ten numerical digits. This separates local adjacency from the global requirement to have seen every digit.
New to topics? Read the docs here!