An analog clock has 2 hands*: Hour and minute.
These hands circle the clock's face as time goes by. Each full rotation of the minute hand results in 1/12th of a rotation of the hour hand. 2 full rotations of the hour hand signifies a full day.
As these hands are fixed to the same central point, and rotate around that point, you can always calculate the angle between the hands. In fact there are 2 angles at any given time; A larger one, and a smaller one (sometimes they will both equal 180, but that's not important)
*Our hypothetical clocks don't have second hands
Task
Given a time in 24 hour format, output the smaller angle between the hands, in degrees. If the hands are directly opposite eachother (such as at 6:00
, 18:00
etc) output 180
Rules
Input may be taken as:
- A delimiter separated string: 6:32
, 14.26
- 2 separate values, strings or ints: 6, 32
, 14, 26
- An array of 2 values, strings or ints: [6, 32]
, [14, 26]
You may also optionally specify that your answer requires inputs be padded to 2 digits (assuming you take strings), ie: 06:32
, 06, 32
, [06, 32]
You may also optionally reverse the order of the inputs, taking minute then hour, ie: 32:6
, 32, 6
, [26, 14]
Hour will be an integer value between 0
and 23
(inclusive)
Minute will be an integer value between 0
and 59
(inclusive)
You can assume that the minute hand snaps to increments of 6 degrees along the face (one evenly-spaced position for each minute value)
You can assume that the hour hand snaps to increments of 0.5 degrees along the face (one evenly-spaced position for each minute value per hour value)
Output must be given in degrees, not radians. You may include a trailing .0
for whole numbers
Scoring
This is code-golf so fewest bytes in each language wins!
Testcases
Input: 06:32
Output: 4
Input: 06:30
Output: 15
Input: 18:32
Output: 4
Input: 06:01
Output: 174.5
Input: 00:00
Output: 0
Input: 00:01
Output: 5.5
Input: 12:30
Output: 165
Input: 6:00
Output: 180
Input: 23:59
Output: 5.5
00:59 -> 35.5
(a small value of \$h\$ with a large value of \$m\$ is likely to make some implementations fail). \$\endgroup\$