I cannot understand the solution to the following programming problem. I will be very thankful for you help!
Given a time, calculate the angle between the hour and minute hands
Solution:
• Angle between the minute hand and 12 o'clock: 360 * m / 60
• Angle between the hour hand and 12 o'clock:
360 * (h % 12) / 12 + 360 * (m / 60) * (1 / 12)
• Angle between hour and minute:
(hour angle - minute angle) % 360
This reduces to
(30h - 5.5m)%360
After $x$ hours of time, the hour hand travels $x / 12$ rotations around the clock. So after $x$ minutes, it travels $x / (60 \cdot 12) = x / 720$.
After $x$ minutes of time, the minute hand travels $x / 60$ rotations around the clock.
At 12:00, both the hour and the minute hand are at position $0$.
Given a time
hh:mm, first figure out how many minutes it has been since 12:00. This will be $60$ times the number of hourshh, plus the number of minutesmm. Set this value as $x$. Then you get that the minute hand has traveled $x / 60$ rotations, and the hour hand has traveled $x / 720$ rotations. Subtracting the two, the angle between them is $(x / 60) - (x / 720) = 11 x / 720$ rotations. Next, convert this number of rotations to degrees by multiplying by $360$; you get $11x / 2$ degrees. However, you need to reduce this mod $360$, so that the angle you get is between $180$ and $-180$. Finally, if it's negative, return the absolute value of the result.