hackathon/question/q04/part1.go

24 lines
456 B
Go

2022-04-29 06:56:26 +07:00
package q04
func waterCorners(grid [][]rune, x, y int) int {
isWater := func(x, y int) int {
if x < 0 || y < 0 || x >= len(grid) || y >= len(grid[x]) || grid[x][y] == ' ' {
return 1
}
return 0
}
return isWater(x-1, y) + isWater(x+1, y) + isWater(x, y-1) + isWater(x, y+1)
}
func solveP1(grid [][]rune) int {
var ps int
for x := range grid {
for y := range grid[x] {
if waterCorners(grid, x, y) == 3 {
ps++
}
}
}
return ps
}