summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Krasin <imkrasin@gmail.com>2012-03-30 21:32:37 +0000
committerIvan Krasin <imkrasin@gmail.com>2012-03-30 21:32:37 +0000
commite6b19e29cb859745913923715496c841ea27b8a4 (patch)
tree22b116f221425888535bf83c55b496e95305d0dc
parent6933b5bcf9635020acb56ba171768ae4ae375642 (diff)
downloadgcd-e6b19e29cb859745913923715496c841ea27b8a4.tar.gz
Don't use flag package, because in this case we only want raw arguments. Use os.Args instead. Make use of append()
-rw-r--r--gcd.go24
1 files changed, 10 insertions, 14 deletions
diff --git a/gcd.go b/gcd.go
index 62a024b..21e5371 100644
--- a/gcd.go
+++ b/gcd.go
@@ -21,8 +21,8 @@ package main
// Both Google Go and GCC issue an error "imported and not used",
// if imported and not used :-)
import (
- "flag"
"fmt"
+ "os"
"strconv"
)
@@ -45,18 +45,14 @@ func gcdn(ns []uint64) (r uint64) {
}
func main() {
- flag.Parse() // without this 6g will give flag.NArg() = 0 next (WTF?)
- n := flag.NArg()
- if n > 0 {
- ns := make([]uint64, n) // We have garbage collector!
-
- // Or: for i := range ns, since range of ns is equal to flag.NArg()
- for i := 0; i < n; i++ {
- // Drop the second return value (error code):
- ns[i], _ = strconv.ParseUint(flag.Arg(i), 0, 64)
- }
-
- g := gcdn(ns)
- fmt.Printf("%v\n", g)
+ if len(os.Args) == 0 {
+ return
}
+ var ns []uint64 // We have garbage collector!
+ for _, arg := range os.Args {
+ // Drop the second return value (error code):
+ v, _ := strconv.ParseUint(arg, 0, 64)
+ ns = append(ns, v)
+ }
+ fmt.Printf("%v\n", gcdn(ns))
}