An old industrial pressure gauge has two needles sharing one dial face and center pivot, moving the way the hands of a clock do. The primary needle completes exactly one full revolution every 12 reading-units and drifts smoothly along with the sub-reading too, so at reading (h, m) it has swept 30h + 0.5m degrees clockwise from the top of the dial. The secondary needle completes exactly one full revolution every 60 sub-units and has swept exactly 6*m degrees clockwise from the top at sub-reading m. Given a reading expressed as an integer h (0-11) and an integer m (0-59), report the smaller of the two angles formed between the needles — the angle measured the short way around the dial, never more than 180 degrees.
A single line with two integers h and m, separated by a space.
Print the smaller angle between the two needles in degrees, rounded to exactly 5 digits after the decimal point.
Example 1
Input
3 30
Expected
75.00000
Explanation
At h=3, m=30 the primary needle has swept 30*3 + 0.5*30 = 105 degrees and the secondary needle has swept 6*30 = 180 degrees; the difference is 75 degrees, and since 75 is already at most 180, that is the answer: 75.00000.
Example 2
Input
9 45
Expected
22.50000
Explanation
At h=9, m=45 the primary needle has swept 30*9 + 0.5*45 = 292.5 degrees and the secondary needle has swept 6*45 = 270 degrees; the raw difference is 22.5 degrees, which is already the smaller angle since 360-22.5=337.5 is larger, giving 22.50000.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →