aboutsummaryrefslogtreecommitdiff
path: root/challenge-271
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-05-27 12:46:56 +0100
committerGitHub <noreply@github.com>2024-05-27 12:46:56 +0100
commit79e369c86f3f2791c2b3d43def86c90c53b92b2c (patch)
tree77efcf96404a6a63e26d14cfa4b27b3aea94836f /challenge-271
parent72abeccd330b38f170d2f8b46692408519f27289 (diff)
parent2f7f51dcb4170c6817a93bd1dd52ad59272ecec3 (diff)
downloadperlweeklychallenge-club-79e369c86f3f2791c2b3d43def86c90c53b92b2c.tar.gz
perlweeklychallenge-club-79e369c86f3f2791c2b3d43def86c90c53b92b2c.tar.bz2
perlweeklychallenge-club-79e369c86f3f2791c2b3d43def86c90c53b92b2c.zip
Merge pull request #10165 from pokgopun/pwc271
pwc271 solution in go - tidy up variables
Diffstat (limited to 'challenge-271')
-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() {