Skip to content

Instantly share code, notes, and snippets.

@alldroll
Created July 14, 2020 08:21
Show Gist options
  • Save alldroll/2ac5246e190eafab034f4ea73c5c7e58 to your computer and use it in GitHub Desktop.
Save alldroll/2ac5246e190eafab034f4ea73c5c7e58 to your computer and use it in GitHub Desktop.
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