Created
February 10, 2018 07:14
-
-
Save icholy/2e1e930929e08027fb1e5652beb6715d 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
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