Clock Triangles

Problem #55

Tags: geometry puzzle

Who solved this?

Previous:Off-Axis Cable Bundling Next:Clock Triangles II


It's raining outside, and Stephen is bored indoors. He watches the clock on his bedroom wall as the time passes, ticking along each second. There are 60 'spots' on the clock where each hand could rest. The second hand ticks to the next spot every second, and the minute hand ticks to the next spot every 60 seconds. The hour hand must travel around the entire clock once every 12 hours, and so it ticks to the next spot every 12 minutes. The hands do not move in between ticks, and all hands point directly upwards at noon.

He notices that on this particular clock the hands are all the same length, with small dots at the end of each hand. He imagines a three lines connecting these dots forming an imaginary triangle which shifts slightly with each passing tick. He notices that the triangle formed may have various different shapes depending on the time.

However, it's quickly clear to Stephen that not all of the above possibilities appear with equal frequency. For example in the 15 seconds between 01:00:00 and 01:01:00, he counts 4 acute triangles, 52 obtuse triangles, and 2 right triangles (understand that no triangle is formed for 2 seconds).

Problem Statement

Given a start time and an end time, return the total quantity of acute, obtuse, and right triangles formed during that time period. Times are given in the format HH:MM:SS. Only the period between the two times should be considered, which does not include the "end" second. For example between the start time of 09:12:34 and end time of 09:12:36, only the triangles formed during the seconds 09:12:34 and 09:12:35 should be considered.

Also note that all times are given using the 12-hour format. It should be understood that 4 hours would pass between 10:00:00 and 02:00:00.

Input Data
First line will be Q, the quantity of testcases.
Q lines will then follow, each with two space-separated time values t_start and t_end.

Answer
Should consist of 3 * Q space-separated integers, corresponding to the quantity of acute, obtuse, and right triangles which are formed per the above rules between the specified times in each testcase.

Example

input data:
4
10:29:22 10:29:23
10:29:21 10:29:24
10:29:20 02:34:56
12:00:01 12:00:00

answer:
0 0 1 1 1 1 3157 10147 650 9744 29232 2088
You need to login to get test data and submit solution.