diff options
author | Ivan Krasin <imkrasin@gmail.com> | 2012-03-30 21:08:27 +0000 |
---|---|---|
committer | Ivan Krasin <imkrasin@gmail.com> | 2012-03-30 21:08:27 +0000 |
commit | 562f33073053f92e5d1995a9b2b16057d03210b3 (patch) | |
tree | 89d80ff336655491060d825fd12c5da7af251b7b | |
parent | 5782cfb5d6705a2ab70a9f950bfca3d4d81c16e4 (diff) | |
download | gcd-562f33073053f92e5d1995a9b2b16057d03210b3.tar.gz |
gcd.go: go fmt
-rw-r--r-- | gcd.go | 59 |
1 files changed, 29 insertions, 30 deletions
@@ -23,39 +23,38 @@ import "fmt" import "flag" import "strconv" -func gcd2 (a, b uint) uint { - if b == 0 { - return a - } - /* 6g issues an error "function ends without a return statement", - if we use if ... {... return} else {... return}. - But GCC doesn't. - */ - return gcd2(b, a % b) +func gcd2(a, b uint) uint { + if b == 0 { + return a + } + /* 6g issues an error "function ends without a return statement", + if we use if ... {... return} else {... return}. + But GCC doesn't. + */ + return gcd2(b, a%b) } -func gcdn (ns []uint) uint { - var r uint // zero by default - for i := range ns { - r = gcd2(r, ns[i]) - } - return r +func gcdn(ns []uint) uint { + var r uint // zero by default + for i := range ns { + r = gcd2(r, ns[i]) + } + return r } 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! - - // 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)) - } - - g := gcdn(ns) - fmt.Printf("%v\n", g) - } + 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! + + // 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)) + } + + g := gcdn(ns) + fmt.Printf("%v\n", g) + } } - |