Created
January 20, 2018 15:10
-
-
Save Neverik/a3764c1f71c9030d88144e602f68bbc5 to your computer and use it in GitHub Desktop.
Clock handle problem solution
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
#self-adjusting clock class | |
class Clock: | |
def __init__(self,h,m,s): | |
self.s = s | |
self.m = m + self.s/60 | |
self.h = h + self.m/60 | |
def angle_hm(self): | |
return abs(self.h - self.m) | |
def angle_ms(self): | |
return abs(self.m - self.s) | |
#my own fraction class | |
class Fraction: | |
def __init__(self,a,b,c=0): | |
self.a = a | |
self.b = b | |
self.c = c | |
def __call__(self): | |
return self.a/self.b + self.c | |
def __str__(self): | |
return str(self.c) + " " + str(self.a) + "/" + str(self.b) | |
''' | |
The clock shows 1:00 PM. Find the closest time when the hour and minute hands will match. | |
Choose an answer: | |
13 hours 5 minutes 27 seconds | |
13 hours 6 minutes | |
13 hours 5 minutes 27 and 7/11 seconds | |
13 hours 5 minutes | |
13 hours 5 minutes 27 and 3/11 seconds | |
''' | |
p = [Fraction(3,11,27),Fraction(7,11,27),Fraction(1,1,27),Fraction(1,1,60)] | |
o = map(lambda x: Clock(1,5,x()), p) | |
r = map(lambda x: x.angle_hm(), o) | |
r = list(r) | |
l = min(r) | |
li = r.index(l) | |
print(p[li]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment