-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (65 loc) · 1.16 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
72
73
74
75
76
77
78
79
80
package main
import (
"github.com/danvolchek/AdventOfCode/lib"
)
type pos struct {
x, y int
}
type gifter struct {
position pos
gifts map[pos]int
}
func (g *gifter) Move(instruction byte) {
switch instruction {
case '^':
g.position.y -= 1
case 'v':
g.position.y += 1
case '>':
g.position.x += 1
case '<':
g.position.x -= 1
default:
panic(string(instruction))
}
g.gifts[g.position] += 1
}
func solve(instructions []byte) int {
santa := gifter{
gifts: map[pos]int{
{x: 0, y: 0}: 1,
},
}
roboSanta := gifter{
gifts: map[pos]int{
{x: 0, y: 0}: 1,
},
}
santaTurn := true
for _, instruction := range instructions {
if santaTurn {
santa.Move(instruction)
} else {
roboSanta.Move(instruction)
}
santaTurn = !santaTurn
}
gotGifts := make(map[pos]bool)
for position := range santa.gifts {
gotGifts[position] = true
}
for position := range roboSanta.gifts {
gotGifts[position] = true
}
return len(gotGifts)
}
func main() {
solver := lib.Solver[[]byte, int]{
ParseF: lib.ParseBytes,
SolveF: solve,
}
solver.Expect("^v", 3)
solver.Expect("^>v<", 3)
solver.Expect("^v^v^v^v^v", 11)
solver.Verify(2631)
}