Skip to content

Instantly share code, notes, and snippets.

@icholy
Created February 10, 2018 07:14
Show Gist options
  • Save icholy/2e1e930929e08027fb1e5652beb6715d to your computer and use it in GitHub Desktop.
Save icholy/2e1e930929e08027fb1e5652beb6715d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
for i := 0; i < 360; i++ {
fmt.Println(DegreeDifference(0, i))
}
}
func DegreeDifference(from, to int) int {
if from == to {
return 0
}
var forward, backward int
if from < to {
forward = to - from
backward = (from + 360) - to
} else {
forward = from - to
backward = (to + 360) - from
}
if forward < backward {
return forward
} else {
return -backward
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment