Skip to content

Instantly share code, notes, and snippets.

@stamaniorec
Last active October 31, 2015 11:57
Show Gist options
  • Select an option

  • Save stamaniorec/a48d7811d2cb97754eec to your computer and use it in GitHub Desktop.

Select an option

Save stamaniorec/a48d7811d2cb97754eec to your computer and use it in GitHub Desktop.
#algo #python
# 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