44
3
Given two integers, A and B, output A if A-B (A minus B) is in A-B (A to B), otherwise output B.
"A minus B" is standard subtraction.
"A to B" is the range of integers starting at A and ending at B, including both A and B. For example:
1 to 4: 1, 2, 3, 4
-2 to 5: -2, -1, 0, 1, 2, 3, 4, 5
3 to -1: 3, 2, 1, 0, -1
7 to 7: 7
The shortest code in bytes wins.
Test Cases
A B Output
1 4 4
-2 5 5
3 -1 -1
7 7 7
90 30 90
90 -30 -30
-90 30 30
-90 -30 -90
-2 -2 -2
-2 -1 -2
-2 0 -2
-2 1 1
-2 2 2
-1 -2 -2
-1 -1 -1
-1 0 -1
-1 1 1
-1 2 2
0 -2 -2
0 -1 -1
0 0 0
0 1 1
0 2 2
1 -2 -2
1 -1 -1
1 0 1
1 1 1
1 2 2
2 -2 -2
2 -1 -1
2 0 2
2 1 2
2 2 2
1@Okx The CMC asked for a Boolean. – Dennis – 2017-03-09T02:45:18.493