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
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
18:00 etc) output 180
Input may be taken as:
- A delimiter separated string:
- 2 separate values, strings or ints:
- An array of 2 values, strings or ints:
You may also optionally specify that your answer requires inputs be padded to 2 digits (assuming you take strings), ie:
You may also optionally reverse the order of the inputs, taking minute then hour, ie:
Hour will be an integer value between
Minute will be an integer value between
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
This is code-golf so fewest bytes in each language wins!
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