Last active
October 31, 2015 11:57
-
-
Save stamaniorec/a48d7811d2cb97754eec to your computer and use it in GitHub Desktop.
#algo #python
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
| # Given a time, calculate the angle between the hour and minute hands on a clock. | |
| hour = 3 | |
| minutes = 27 | |
| def solution(hour, minutes): | |
| minute_percentage = float(minutes) / 60 | |
| minute_degrees = minute_percentage * 360 | |
| hour_degrees = float(hour)/12 * 360 | |
| next_hour = (hour + 1) % 12 | |
| if hour == 11: | |
| next_hour_degrees = 360 | |
| else: | |
| next_hour_degrees = float(next_hour)/12 * 360 | |
| in_between = minute_percentage * (next_hour_degrees - hour_degrees) | |
| answer = minute_degrees - (hour_degrees + in_between) | |
| return answer | |
| print(solution(3,27)) | |
| print(solution(9,40)) | |
| print(solution(11,10)) | |
| print(solution(11,50)) | |
| # The "official solution" formula is 30 * hours - 5.5 * minutes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment