Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created September 12, 2017 14:08
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 thinkphp/0677b4493bf86e371676e8ce9741ddf4 to your computer and use it in GitHub Desktop.
Save thinkphp/0677b4493bf86e371676e8ce9741ddf4 to your computer and use it in GitHub Desktop.
Go by Example with struct, method and euclid
package main
import "fmt"
type Pair struct {
a, b int
}
func (n *Pair) euclid() int {
for n.b != 0 {
n.a, n.b = n.b, n.a % n.b
}
return n.a
}
func main() {
a := 10
b := 4
c := 10
d := 3
r := Pair{a,b}
f := Pair{c,d}
fmt.Printf("GDC<%d,%d> = %d\n", a, b, r.euclid())
fmt.Printf("GDC<%d,%d> = %d\n", c, d, f.euclid())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment