Created
October 9, 2012 15:26
-
-
Save christianp/3859511 to your computer and use it in GitHub Desktop.
two-way prime times
This file contains 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
00:03 -- 23:57 | |
00:13 -- 23:47 | |
00:19 -- 23:41 | |
01:09 -- 22:51 | |
01:39 -- 22:21 | |
01:57 -- 22:03 | |
02:23 -- 21:37 | |
02:29 -- 21:31 | |
03:07 -- 20:53 | |
03:31 -- 20:29 | |
03:49 -- 20:11 | |
04:09 -- 19:51 | |
06:01 -- 17:59 | |
06:07 -- 17:53 | |
06:13 -- 17:47 | |
06:19 -- 17:41 | |
07:33 -- 16:27 | |
07:39 -- 16:21 | |
07:51 -- 16:09 | |
08:11 -- 15:49 | |
08:29 -- 15:31 | |
09:07 -- 14:53 | |
09:37 -- 14:23 | |
10:33 -- 13:27 | |
10:39 -- 13:21 | |
11:23 -- 12:37 | |
11:29 -- 12:31 | |
27 pairs of two-way prime times |
This file contains 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
def digits(n): | |
if n=='': | |
return None | |
digits=[int(x) for x in list(str(n))] | |
digits = [0]*(4-len(digits))+digits | |
return digits | |
def to_time(n): | |
a,b,c,d=digits(n) | |
hour = a*10+b | |
minutes = c*10+d | |
return hour,minutes | |
def valid_time(time): | |
hour,minutes=time | |
return minutes<60 and (hour<12 or (hour==12 and minutes<31)) | |
def prime_time(hour,minutes): | |
return (hour*100+minutes) in primes | |
primes=[int(n) for n in open('primes.txt').read().split('\n') if len(n)>0] | |
primetimes=[to_time(p) for p in primes if valid_time(to_time(p))] | |
twoway_primetimes = [[(hour,minutes),(23-hour,60-minutes)] for hour,minutes in primetimes if prime_time(23-hour,60-minutes)] | |
def display_time(time): | |
hour,minutes = time | |
return '%s:%s' % (str(hour).zfill(2),str(minutes).zfill(2)) | |
for t1,t2 in twoway_primetimes: | |
print('%s -- %s' % (display_time(t1),display_time(t2))) | |
print('%i pairs of two-way prime times' % len(twoway_primetimes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment