Last active
September 3, 2016 00:11
-
-
Save bblay/f898fe9d919b0dbceac759d28d28b9a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mins_per_day = 24 * 60 | |
def identify_overtakes(num_hours): | |
num_mins = num_hours * 60 | |
overtakes = [] | |
last_diffs = [0.0, 0.0] | |
for i in xrange(num_mins): | |
hour = (i / 60) % 12 | |
minute = (i % 60) % mins_per_day | |
# work the hand positions out as fractions 0.0 -> 1.0 | |
hour_frac = ((i / 60.0) % 12) / 12.0 | |
min_frac = (i % 60) / 60.0 | |
diff = min_frac - hour_frac | |
# we can't be more than half way away, e.g either side of vertical | |
if diff > 0.5: | |
diff = diff - 1.0 | |
if diff < -0.5: | |
diff = diff + 1.0 | |
if diff > 0.0: | |
if last_diffs[-1] < 0.0 or (last_diffs[-1] == 0.0 and last_diffs[-2] < 0.0): | |
overtakes.append((hour, minute)) | |
last_diffs = last_diffs[1:] + [diff] | |
return overtakes | |
if __name__ == '__main__': | |
num_hours = 24 * 5 | |
overtakes = identify_overtakes(num_hours) | |
for i in overtakes: | |
print '{:02d}:{:02d}'.format(*i) | |
print '{} overtakes in {} hours'.format(len(overtakes), num_hours) | |
# Here are the results: | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 00:01 | |
# 01:06 | |
# 02:11 | |
# 03:17 | |
# 04:22 | |
# 05:28 | |
# 06:33 | |
# 07:39 | |
# 08:44 | |
# 09:50 | |
# 10:55 | |
# 109 overtakes in 120 hours | |
On line 12, minute = (i % 60) % mins_per_day
, the 2nd % does nothing and might as well be removed.
To clarify, this code steps forwards minutely and records every overtake.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In 5 days we see 10 12-hour periods, each with the same 10 overlap times: 01:06, 02:11, 03:17, 04:22, 05:28, 06:33, 07:39, 08:44, 09:50, 10:55 with each of the 9 joins causing an overlap at 00:01.