aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-05-27 12:48:53 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-05-27 12:48:53 +0100
commit141a2c357124c00dda182472650be78c509efd97 (patch)
treee3deec3a685e79f53c39dfdef459fffb8767ed3b
parent121b188ff9875f14ddd1567ad62ceb734d1ed226 (diff)
parent79e369c86f3f2791c2b3d43def86c90c53b92b2c (diff)
downloadperlweeklychallenge-club-141a2c357124c00dda182472650be78c509efd97.tar.gz
perlweeklychallenge-club-141a2c357124c00dda182472650be78c509efd97.tar.bz2
perlweeklychallenge-club-141a2c357124c00dda182472650be78c509efd97.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-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() {