Skip to content

Instantly share code, notes, and snippets.

@bblay
Last active September 3, 2016 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bblay/f898fe9d919b0dbceac759d28d28b9a7 to your computer and use it in GitHub Desktop.
Save bblay/f898fe9d919b0dbceac759d28d28b9a7 to your computer and use it in GitHub Desktop.
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
@bblay
Copy link
Author

bblay commented Sep 2, 2016

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.

@bblay
Copy link
Author

bblay commented Sep 2, 2016

On line 12, minute = (i % 60) % mins_per_day, the 2nd % does nothing and might as well be removed.

@bblay
Copy link
Author

bblay commented Sep 3, 2016

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