make pointers so we don't dereference constantly
This commit is contained in:
parent
f7cc2a9dd3
commit
c6b9c1586e
16
cmd/gcd.go
16
cmd/gcd.go
|
|
@ -27,10 +27,10 @@ import (
|
||||||
var extended bool
|
var extended bool
|
||||||
|
|
||||||
func gcd(cmd *cobra.Command, args []string) {
|
func gcd(cmd *cobra.Command, args []string) {
|
||||||
var x big.Int
|
x := new(big.Int)
|
||||||
var y big.Int
|
y := new(big.Int)
|
||||||
var z big.Int
|
z := new(big.Int)
|
||||||
var w big.Int
|
w := new(big.Int)
|
||||||
|
|
||||||
bezouts := make([]big.Int, len(args))
|
bezouts := make([]big.Int, len(args))
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ func gcd(cmd *cobra.Command, args []string) {
|
||||||
log.Fatal("invalid input " + s)
|
log.Fatal("invalid input " + s)
|
||||||
}
|
}
|
||||||
|
|
||||||
z.GCD(&x, &y, &z, &w)
|
z.GCD(x, y, z, w)
|
||||||
|
|
||||||
if !extended {
|
if !extended {
|
||||||
continue
|
continue
|
||||||
|
|
@ -48,15 +48,15 @@ func gcd(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
for j, c := range bezouts {
|
for j, c := range bezouts {
|
||||||
if j == i {
|
if j == i {
|
||||||
bezouts[j].Set(&y)
|
bezouts[j].Set(y)
|
||||||
} else {
|
} else {
|
||||||
bezouts[j].Mul(&c, &x)
|
bezouts[j].Mul(&c, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(&z)
|
fmt.Print(z)
|
||||||
if extended {
|
if extended {
|
||||||
for _, c := range bezouts {
|
for _, c := range bezouts {
|
||||||
fmt.Printf(" %s", &c)
|
fmt.Printf(" %s", &c)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue