Problem Link
Difficulty
Simple
Pre-requisites
Basic programming language constructions
Problem
Find all times in the HH:MM format, such that the absolute value of the angle between hours’ and minutes’ hands is equal to the given value.
Explanation
Let us iterate through all possible values of times and check the absolute value of the angle between hours’ and minutes’ hands. This angle is calculated as the difference between two angles, namely, A - the angle of hours’ hand and B - the angle of minutes’ hand.
Let us define the rules for calculating the angles of the hands:
-
Every minute hours’ hand moves by 360/(12*60)=1/2 degrees, since 360 degrees is the full circle and in every of 12 hour there are 60 minutes. Every minute the hand shifts by the same angle. So, we get A = N/2, where N is the number of minutes since the beginning of the day (00:00).
-
Every minute minutes’ hand moves by 360/60 = 6 degrees. So, B = M*6, where M is the current number of minutes (not taking hours into account).
So, the solution consists of iterating all the possible values of times and checking the corresponding absolute angles. In total there are only 60*12 = 720 possible times.
Setter’s Solution
Can be found here
Tester’s Solution
Can be found here