You have locked your bike with a combination lock of 3 digits. Now you want to go for a ride and need to unlock it with the help of following program.
Input
1st parameter
The digit combination of your lock in locked state. It must be different from the 2nd parameter (=the combination of unlocked state). (Or else your bike could be stolen!)
Range 000..999. Leading zeros must not be omitted.
2nd parameter
The digit combination of your lock in unlocked state. This value is your goal.
Range 000..999. Leading zeros must not be omitted.
Output
A list of each state of the combination lock after each "rotation" including the initial state (which is always the 1st parameter) and the last step (which is always the 2nd paramater).
Algorithm
You start "rotating" the first digit one by one until you reach the correct digit in unlocked state. But, because you are in knowledge of the whole unlock-code, you rotate the digit in the direction in which you need the smallest amount of rotations to reach the digit in unlocked state. In case of a tie you can choose whatever direction you prefer.
When you have reached the correct first digit, you start the same procedure with the 2nd and then with the 3rd.
The order of digits is to understand as a circle:
... 9 0 1 2 3 4 5 6 7 8 9 0 1 2 ...
This means, that the smallest amount of rotations from 1 to 9 is not
1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9
= 8
but
1 -> 0 -> 9
= 2.
Notes
- You can rely on Default I/O rules
- You can change the order of the parameters.
Examples
Example 1, correct
Input: 999 001
Output:
999
099
009
000
001
Example 2, correct
Input: 000 292
Output:
000
100
200
290
291
292
Example 3, wrong output
Input: 999 121
Wrong output:
999
899 // Wrong because wrong rotation direction.
799
699
...
Correct output:
999
099
199
109
119
129
120
121
Example 4, wrong input
Input: 1 212 // Wrong because no leading zeros.
This is code-golf the shortest answer wins.