Skip to content

Instantly share code, notes, and snippets.

@jhinrichsen
Created April 12, 2018 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhinrichsen/5ef2501325b92f493ae2abc356395cea to your computer and use it in GitHub Desktop.
Save jhinrichsen/5ef2501325b92f493ae2abc356395cea to your computer and use it in GitHub Desktop.
GCD (greatest common denominator) commandline utility, implementation based on Euclid
package main
import (
"os"
"strconv"
)
func euclid(i, j int) int {
for i != j {
if i > j {
i -= j
} else {
j -= i
}
}
return i
}
func main() {
n1, err := strconv.Atoi(os.Args[1])
if err != nil {
panic(err)
}
n2, err := strconv.Atoi(os.Args[2])
if err != nil {
panic(err)
}
os.Exit(euclid(n1, n2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment