Problem Statement
You have a very simple calculator that has a display and two buttons. The buttons are labelled "-2" and "+3". Whenever you press a button, the corresponding operation is applied to the number shown on the display. For example, if the display shows the number 10, pressing the "-2" button changes it to 10-2 = 8, while pressing the "+3" button changes it to 10+3 = 13.
You are given the
Definition
- Class:
- BinaryCalculator
- Method:
- minimumSteps
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int minimumSteps(int a, int b)
- (be sure your method is public)
Constraints
- a will be between 1 and 100, inclusive.
- b will be between 1 and 100, inclusive.
Examples
10
14
Returns: 3
One solution is to press the button +3 to get 13, then -2 to get 11 and finally +3 to get 14. There are other ways of obtaining the same result, but none of them is shorter than 3 presses.
23
23
Returns: 0
As a = b, you don't need to press any buttons.
3
97
Returns: 33
3
98
Returns: 35
3
99
Returns: 32
10
11
Returns: 2
10
12
Returns: 4
10
13
Returns: 1
10
10
Returns: 0
99
99
Returns: 0
90
89
Returns: 3
90
88
Returns: 1
90
87
Returns: 4
80
10
Returns: 35
80
9
Returns: 38
18
12
Returns: 3
The only optimal solution is to press "-2" three times in a row.
23
62
Returns: 13
2
4
Returns: 4
3
2
Returns: 3
13
12
Returns: 3
1
3
Returns: 4
2
1
Returns: 3
87
44
Returns: 24
10
15
Returns: 5
5
4
Returns: 3
3
5
Returns: 4
2
5
Returns: 1
2
7
Returns: 5
1
9
Returns: 6
6
1
Returns: 5
9
2
Returns: 6