-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (58 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"github.com/danvolchek/AdventOfCode/lib"
)
func parse(char byte) int {
return int(char - '0')
}
func isVisible(x, y int, grid [][]int) bool {
v := grid[x][y]
visibleX1 := true
for i := x - 1; i > -1; i-- {
if grid[i][y] >= v {
visibleX1 = false
break
}
}
visibleX2 := true
for i := x + 1; i < len(grid); i++ {
if grid[i][y] >= v {
visibleX2 = false
break
}
}
visibleY1 := true
for i := y - 1; i > -1; i-- {
if grid[x][i] >= v {
visibleY1 = false
break
}
}
visibleY2 := true
for i := y + 1; i < len(grid[x]); i++ {
if grid[x][i] >= v {
visibleY2 = false
break
}
}
return visibleX1 || visibleX2 || visibleY1 || visibleY2
}
func solve(lines [][]int) int {
sum := 0
for x := 0; x < len(lines); x++ {
for y := 0; y < len(lines); y++ {
if isVisible(x, y, lines) {
sum += 1
}
}
}
return sum
}
func main() {
solver := lib.Solver[[][]int, int]{
ParseF: lib.TrimSpace(lib.ParseGrid(parse)),
SolveF: solve,
}
solver.Expect("30373\n25512\n65332\n33549\n35390\n", 21)
solver.Verify(1796)
}