A really nice logical question is “How many times a day do the minute and hour hands of a clock overlap?”. Well that’s easy, 22 times. During the first half of the day, they overlap 11 times: 00:00, ~01:05, ~02:10, and so on, but not ~11:55 (since they overlap at 00:00). In 24 hours, that would be 22 times. I’m not trying to find out how many times, but when does this happen.
Caution! If you think you will lose your time while I solve this task just for the fun of solving it, please don’t go any further.
Let’s think of the hour hand. In one hour, it makes 1/12 of a full circle, which means 1/12 of 360 degrees. So the angular velocity of the hour hand is 30 degrees/hour or 0.5 degrees/min or 1 degree every 2 minutes.
What about the minute hand? It makes a full circle in one hour, which means 6 degrees/min. That’s basic maths, every 6th grader can calculate these. Also, every 6th grader can calculate when do the clock hands overlap, but I’m going to use Python for this task.
Now we should consider that if we are calculating the time when the hands overlap, for example, when the hour is 1, it is better to start checking after 01:05, or in general 5 * h minutes when the hour is h. I am now writing a simple function to calculate the angle of each hand for a given hour:
This would output:
So when the time is 01:05, the hour hand is shifted 32.5 degrees from the base position (which is hour 12) while the minutes hand is shifted 30 degrees from the base position.
Now we are going to “move” the minutes hand by one minute (6 degrees). If we find a time when the minutes and the hour hands are shifted with the same angle, that is when the overlap happens. If the minutes hand passes the hour hand, we found an interval when the minutes hand overlaps the hour hand.
To do this, I changed my program to this:
It outputs this: The hands overlap between 01:05 and 01:06. And it’s true! When it’s 01:05 the hands are respectively at 32.5 degrees and 30 degrees, while at 01:06 they are at 33 and 36 degrees.
Now what we have to do, is add a loop to calculate when does the overlapping happen for any hour from 00:00 to 11:00. Before that, I’d like to add a use case which we already know the result. If the hour is 11 or 12 or 00, we know that the overlap happens at 00:00. so the final code would be:
And the output is:
I wouldn’t like to go ahead and find the second when the overlap happens, but it is possible and it’s not very hard to do it. If you would like to do it, please comment below with a gist of the code.