34
4
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.
May I change the order of two parameters? – tsh – 2019-08-26T07:40:00.157
May we update the digits in any order as long as it's optimal? – Arnauld – 2019-08-26T08:10:59.967
@Arnauld No because I unlock my lock one by one :) – user2190035 – 2019-08-26T08:34:08.700
Can we print same step more than once? For example: "999 099 099 089 ..." – Night2 – 2019-08-26T09:34:32.953
2@Night2 No, since the program should simulate the "unlocking process" of a combination look. – user2190035 – 2019-08-26T09:36:44.247
6Related – Luis Mendo – 2019-08-26T11:30:19.133
Do we have to print the first iteration of the lock? – Embodiment of Ignorance – 2019-08-27T02:36:20.970
@EmbodimentofIgnorance yes – user2190035 – 2019-08-27T06:11:20.207
You should provide an example where at least one of the digits needs to be rotated down to go the correct direction. – Greg Martin – 2019-08-27T20:02:22.963
@GregMartin Done – user2190035 – 2019-08-29T06:46:20.103