Created
October 15, 2017 16:21
-
-
Save joshuashaffer/24e9d3de5f41aaca1fbb605f762fb115 to your computer and use it in GitHub Desktop.
Given a time, your mission is to calculate the angle between the hour hand and the minute hand on an analog clock and return it in radians in lowest terms.
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
| import fractions as f | |
| def clockRadian(time): | |
| h, m = tuple(map(int, time.split(':'))) | |
| t = abs((h % 12) * 60 - m * 12 + m) | |
| t = 720 - t if t > 360 else t | |
| if t == 0: | |
| return "0" | |
| a = f.Fraction(t, 360) | |
| b = a.numerator | |
| c = a.denominator | |
| return "{}pi/{} ".format(b if b > 1 else '', c)[0:-1 if c > 1 else -3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment