-
Notifications
You must be signed in to change notification settings - Fork 0
/
day08.go
76 lines (66 loc) · 1.21 KB
/
day08.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
72
73
74
75
76
package main
func findTrees(treeMap [][]int) (int, int) {
var trees int = 0
var scenicScore int = 0
for y, row := range treeMap {
for x, cell := range row {
var upScore int = 0
var downScore int = 0
var leftScore int = 0
var rightScore int = 0
inSight := false
for walkX := x; walkX >= 0; {
walkX--
if walkX == -1 {
inSight = true
break
}
leftScore++
if treeMap[y][walkX] >= cell {
break
}
}
for walkX := x; walkX <= len(row)-1; {
walkX++
if walkX == len(row) {
inSight = true
break
}
rightScore++
if treeMap[y][walkX] >= cell {
break
}
}
for walkY := y; walkY >= 0; {
walkY--
if walkY == -1 {
inSight = true
break
}
upScore++
if treeMap[walkY][x] >= cell {
break
}
}
for walkY := y; walkY <= len(treeMap)-1; {
walkY++
if walkY == len(treeMap) {
inSight = true
break
}
downScore++
if treeMap[walkY][x] >= cell {
break
}
}
currentScore := upScore * downScore * leftScore * rightScore
if currentScore > scenicScore {
scenicScore = currentScore
}
if inSight {
trees++
}
}
}
return trees, scenicScore
}