Skip to content

Instantly share code, notes, and snippets.

@williamhaley
Created December 29, 2018 23:17
Show Gist options
  • Save williamhaley/6679f5cdc8f48ab819e984a5b70687c5 to your computer and use it in GitHub Desktop.
Save williamhaley/6679f5cdc8f48ab819e984a5b70687c5 to your computer and use it in GitHub Desktop.
Calculate the Greatest Common Denominator using GoLang
package main
import (
"fmt"
)
// https://www.reddit.com/r/golang/comments/7b4mt9/greatest_common_divisor/
// GreatestCommonDenominator finds the GCD of two ints
func GreatestCommonDenominator(a, b int) int {
remainder := 0
for b != 0 {
remainder = a % b
a, b, remainder = b, remainder, a
}
return a
}
func main() {
fmt.Println(GreatestCommonDenominator(0, 128))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment