Created
July 14, 2020 08:21
-
-
Save alldroll/2ac5246e190eafab034f4ea73c5c7e58 to your computer and use it in GitHub Desktop.
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
func angleClock(hour int, minutes int) float64 { | |
left, right := hourAngle(hour, minutes), minuteAngle(minutes) | |
if left < right { | |
right, left = left, right | |
} | |
return min(left - right, 360 - left + right) | |
} | |
func hourAngle(hour int, minutes int) float64 { | |
angle := float64((hour % 12) * 30) | |
return angle + (float64(minutes) / 60) * 30 | |
} | |
func minuteAngle(minutes int) float64 { | |
return (float64(minutes) / 60) * 360 | |
} | |
func min(a, b float64) float64 { | |
if a < b { | |
return a | |
} | |
return b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment