Problem list
Log in
#icpc00243 · ICPC NCPC 2016

Jumbled Compass

Bronze III 5.0 s 2048 MB

Jonas is developing the JUxtaPhone and is tasked with animating the compass needle. The API is simple: the compass needle is currently in some direction (between $0$ and $359$ degrees, with north being $0$, east being $90$), and is being animated by giving the degrees to spin it.

If the needle is pointing north, and you give the compass an input of $90$, it will spin clockwise (positive numbers mean clockwise direction) to stop at east, whereas an input of $-45$ would spin it counterclockwise to stop at north west.

The compass gives the current direction the phone is pointing and Jonas' task is to animate the needle taking the shortest path from the current needle direction to the correct direction. Many ifs, moduli, and even an arctan later, he is still not convinced his minimumDistance function is correct; he calls you on the phone.

Input

The first line of input contains an integer $n_1$ ($0 \le n_1 \le 359$), the current direction of the needle. The second line of input contains an integer $n_2$ ($0 \le n_2 \le 359$), the correct direction of the needle.

Output

Output the change in direction that would make the needle spin the shortest distance from $n_1$ to $n_2$. A positive change indicates spinning the needle clockwise, and a negative change indicates spinning the needle counter-clockwise.

If the two input numbers are diametrically opposed, the needle should travel clockwise. I.e., in this case, output $180$ rather than $-180$.

Example 1

Input
315
45
Output
90

Example 2

Input
180
270
Output
90

Example 3

Input
45
270
Output
-135
Source
ICPC NCPC 2016
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code