From 15f2c46559bf98cc10327cfc33d292fe1be5213a Mon Sep 17 00:00:00 2001 From: Ivan Krasin Date: Fri, 30 Mar 2012 21:11:50 +0000 Subject: gcd.go: update to Go1. Use uint64 instead of uint, because strconv.ParseUint returns uint64, and there's no reason to artificially limit the tool to uint (which is now 32 bits) --- gcd.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gcd.go b/gcd.go index 429c22e..2b2bd3d 100644 --- a/gcd.go +++ b/gcd.go @@ -23,7 +23,7 @@ import "fmt" import "flag" import "strconv" -func gcd2(a, b uint) uint { +func gcd2(a, b uint64) uint64 { if b == 0 { return a } @@ -34,8 +34,8 @@ func gcd2(a, b uint) uint { return gcd2(b, a%b) } -func gcdn(ns []uint) uint { - var r uint // zero by default +func gcdn(ns []uint64) uint64 { + var r uint64 // zero by default for i := range ns { r = gcd2(r, ns[i]) } @@ -46,12 +46,12 @@ func main() { flag.Parse() // without this 6g will give flag.NArg() = 0 next (WTF?) n := flag.NArg() if n > 0 { - ns := make([]uint, n) // We have garbage collector! + 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.Atoui(flag.Arg(i)) + ns[i], _ = strconv.ParseUint(flag.Arg(i), 0, 64) } g := gcdn(ns) -- cgit v1.2.3