>>103490746
part2. Yesh could've combined. I just copy/pasted and modified.
dcorners := [][]rc{
{{0, -1}, {-1, 0}, {-1, -1}},
{{-1, 0}, {0, 1}, {-1, 1}},
{{0, 1}, {1, 0}, {1, 1}},
{{1, 0}, {0, -1}, {1, -1}},
}
for r, row := range gmap {
for c, col := range row {
trc := rc{r, c}
_, ok := bighist[trc]
if ok {
continue
}
cplant := col
bighist[trc] = struct{}{}
hist := make(map[rc]int)
var crc rc
pending := []rc{trc}
hist[trc] = 0
corcount := 0
for len(pending) > 0 {
crc, pending = pending[0], pending[1:]
bighist[crc] = struct{}{}
for _, dd := range ddirs {
drc := crc.add(dd)
if drc.r < 0 || drc.r > maxr || drc.c < 0 || drc.c > maxc {
hist[crc] += 1
continue
}
dplant := gmap[drc.r][drc.c]
if cplant != dplant {
hist[crc] += 1
continue
}
if _, ok := hist[drc]; ok {
continue
}
hist[drc] = 0
pending = append(pending, drc)
}
var p1 byte
var p2 byte
var p3 byte
for _, dc := range dcorners {
s1 := true
s2 := true
s3 := true
d1 := crc.add(dc[0])
d2 := crc.add(dc[1])
d3 := crc.add(dc[2])
if d1.r < 0 || d1.r > maxr || d1.c < 0 || d1.c > maxc {
s1 = false
}
if s1 {
p1 = gmap[d1.r][d1.c]
s1 = cplant == p1
}
if d2.r < 0 || d2.r > maxr || d2.c < 0 || d2.c > maxc {
s2 = false
}
if s2 {
p2 = gmap[d2.r][d2.c]
s2 = cplant == p2
}
if d3.r < 0 || d3.r > maxr || d3.c < 0 || d3.c > maxc {
s3 = false
}
if s3 {
p3 = gmap[d3.r][d3.c]
s3 = cplant == p3
}
if !s1 && !s2 {
corcount++
continue
}
if s1 && s2 && !s3 {
corcount++
continue
}
}
}
fmt.Println("spots", string(cplant), len(hist))
fmt.Println("corcount", string(cplant), corcount)
ssum += corcount * len(hist)
}
}
fmt.Println("sum", ssum)