Using the matchstick numbers here: Count the Matchsticks
_ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_|
|_| | |_ _| | _| |_| | |_| _|
How many matchsticks must be moved and/or removed to change one number into another?
You will take two single digit numbers (0 to 9) as input (however works for you language), and return the number of moves needed to convert from the first input number to second input number, as though they were written in matchsticks. If no such operation is possible output some sort of 'Error Response' (any consistent output other a than a positive number or zero (if the output is a number, could be from -1 -> -Infinity) or you let the program crash):
Input: 9 0
Output: 1
Input: 8 9
Output: 1
Input: 0 1
Output: 4
Input: 7 8
Output: 'Error response'
Input: 8 7
Output: 4
Input: 2 5
Output: 2
Input: 2 3
Output: 1
Input: 5 6
Output: 'Error response'
Input: 4 4
Output: 0
Input: 6 7
Output: 4
Here is the full table of first and second inputs, and each cell is the output:
input 1 v/input 2 > | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 4 | 2 | 2 | 3 | 2 | 1 | 3 | err | 1 |
1 | err | 0 | err | err | err | err | err | err | err | err |
2 | err | 4 | 0 | 1 | 3 | 2 | err | 3 | err | err |
3 | err | 3 | 1 | 0 | 2 | 1 | err | 2 | err | err |
4 | err | 2 | err | err | 0 | err | err | 2 | err | err |
5 | err | 4 | 2 | 1 | 2 | 0 | err | 3 | err | err |
6 | 1 | 4 | 2 | 2 | 3 | 1 | 0 | 4 | err | 1 |
7 | err | 1 | err | err | err | err | err | 0 | err | err |
8 | 1 | 5 | 2 | 2 | 3 | 2 | 1 | 4 | 0 | 1 |
9 | 1 | 4 | 2 | 1 | 2 | 1 | 1 | 3 | err | 0 |