-
Notifications
You must be signed in to change notification settings - Fork 1
/
day3.go
48 lines (42 loc) · 965 Bytes
/
day3.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
package main
import (
"utils"
)
func run(filepath string, numSantas int) (housesCovered int) {
input := utils.ReadFileToString(filepath)
gridSize := len(input) + 10
houseGrid := make([][]int, gridSize)
for i := range houseGrid {
houseGrid[i] = make([]int, gridSize)
}
var santas [][]int
for i := 0; i < numSantas; i++ {
santas = append(santas, []int{gridSize / 2, gridSize / 2})
}
currentSanta := 0
houseGrid[santas[currentSanta][1]][santas[currentSanta][0]]++
for _, r := range input {
switch r {
case '^':
santas[currentSanta][1]--
case '>':
santas[currentSanta][0]++
case 'v':
santas[currentSanta][1]++
case '<':
santas[currentSanta][0]--
}
houseGrid[santas[currentSanta][1]][santas[currentSanta][0]]++
currentSanta = (currentSanta + 1) % numSantas
}
for y := range houseGrid {
for x := range houseGrid[y] {
if houseGrid[y][x] > 0 {
housesCovered++
}
}
}
return housesCovered
}
func main() {
}