aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manring <michael@manring>2024-05-27 21:33:36 +1000
committerMichael Manring <michael@manring>2024-05-27 21:42:24 +1000
commit2f7f51dcb4170c6817a93bd1dd52ad59272ecec3 (patch)
tree77efcf96404a6a63e26d14cfa4b27b3aea94836f
parent72abeccd330b38f170d2f8b46692408519f27289 (diff)
downloadperlweeklychallenge-club-2f7f51dcb4170c6817a93bd1dd52ad59272ecec3.tar.gz
perlweeklychallenge-club-2f7f51dcb4170c6817a93bd1dd52ad59272ecec3.tar.bz2
perlweeklychallenge-club-2f7f51dcb4170c6817a93bd1dd52ad59272ecec3.zip
pwc271 solution in go - tidy up variables
-rw-r--r--challenge-271/pokgopun/go/ch-1.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/challenge-271/pokgopun/go/ch-1.go b/challenge-271/pokgopun/go/ch-1.go
index d2e9c3e0ba..bbafc1650a 100644
--- a/challenge-271/pokgopun/go/ch-1.go
+++ b/challenge-271/pokgopun/go/ch-1.go
@@ -52,10 +52,6 @@ import (
"github.com/google/go-cmp/cmp"
)
-type answer struct {
- c, i int
-}
-
type row []int
func (rw row) countOne() int {
@@ -72,23 +68,25 @@ func (rw row) countOne() int {
type matrix []row
func (mtx matrix) maxOneRow() int {
- mx := len(mtx[0])
- c := mtx[0].countOne()
- if c == mx {
- return 1
+ idx := 0
+ mx := len(mtx[idx])
+ cnt := mtx[idx].countOne()
+ if cnt == mx {
+ return idx + 1
}
- ans := answer{c: c}
+ cntMx, cntMxIdx := cnt, idx
l := len(mtx)
- for i := 1; i < l; i++ {
- c = mtx[i].countOne()
- if c == mx {
- return i + 1
+ for idx = 1; idx < l; idx++ {
+ cnt = mtx[idx].countOne()
+ if cnt == mx {
+ return idx + 1
}
- if c > ans.c {
- ans = answer{c, i}
+ if cnt > cntMx {
+ cntMx = cnt
+ cntMxIdx = idx
}
}
- return ans.i + 1
+ return cntMxIdx + 1
}
func main() {