add extended flag

This commit is contained in:
filifa 2025-08-11 20:59:43 -04:00
parent 4021a1caed
commit bce95536f7
1 changed files with 13 additions and 1 deletions

View File

@ -24,12 +24,18 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var extended bool
func gcd(cmd *cobra.Command, args []string) { func gcd(cmd *cobra.Command, args []string) {
var x big.Int var x big.Int
var y big.Int var y big.Int
var z big.Int var z big.Int
var w big.Int var w big.Int
if extended && len(args) > 2 {
log.Fatal("--extended unsupported for more than two values")
}
for _, s := range args { for _, s := range args {
_, ok := w.SetString(s, 10) _, ok := w.SetString(s, 10)
if !ok { if !ok {
@ -39,8 +45,12 @@ func gcd(cmd *cobra.Command, args []string) {
z.GCD(&x, &y, &z, &w) z.GCD(&x, &y, &z, &w)
} }
if extended {
fmt.Println(&z, &x, &y)
} else {
fmt.Println(&z) fmt.Println(&z)
} }
}
// gcdCmd represents the gcd command // gcdCmd represents the gcd command
var gcdCmd = &cobra.Command{ var gcdCmd = &cobra.Command{
@ -63,4 +73,6 @@ func init() {
// Cobra supports local flags which will only run when this command // Cobra supports local flags which will only run when this command
// is called directly, e.g.: // is called directly, e.g.:
// gcdCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") // gcdCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
gcdCmd.Flags().BoolVarP(&extended, "extended", "e", false, "also compute the Bezout coefficients")
} }