Created
October 30, 2012 23:25
-
-
Save christianp/3983772 to your computer and use it in GitHub Desktop.
If you think of times hh:mm as ratios, how many unique ratios can a 24-hour clock display?
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
from itertools import product | |
times = product(range(24),range(60)) | |
primes = [2,3,5,7,11,13,17,19,23] #we only need primes < 24 | |
def cancel(a,b): | |
if a==b==0: | |
return (0,0) | |
for p in primes: | |
if a%p==b%p==0: | |
return cancel(a//p,b//p) # a//p is integer division | |
return (a,b) | |
ratios = set(cancel(a,b) for a,b in times) | |
print('%i unique ratios out of %i unique times' % (len(ratios),24*60) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment