Given two bearings between 0 degree and 360 degrees, A and B, what is the most efficient way to compute the minimum rotation required for A to reach B? The rotation can be clockwise (positive) or anti-clockwise (negative). The minimum rotation should be in whichever direction which gives the smaller absolute degrees.
For example,
minRotation(30,20) yields -10.
minRotation(350,20) yields 30.
How do we formulate the function minRotation(A,B)?