-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (60 loc) · 1.53 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
package main
import (
"fmt"
"github.com/Alex-Waring/AoC/utils"
)
func part1(input []string) {
defer utils.Timer("part1")()
board := utils.NewBoard()
for r, row := range input {
for c, char := range row {
board[utils.Position{Row: r, Col: c}] = string(char)
}
}
found := 0
// Check every position to see if it starts an XMAS
for pos, letter := range board {
if letter != "X" {
continue
}
dirs := []utils.Direction{utils.Up, utils.Down, utils.Left, utils.Right, utils.UpRight, utils.UpLeft, utils.DownLeft, utils.DownRight}
for _, dir := range dirs {
word := letter + board[pos.Move(dir, 1)] + board[pos.Move(dir, 2)] + board[pos.Move(dir, 3)]
if word == "XMAS" {
found++
}
}
}
fmt.Println(found)
}
func part2(input []string) {
defer utils.Timer("part2")()
board := utils.NewBoard()
for r, row := range input {
for c, char := range row {
board[utils.Position{Row: r, Col: c}] = string(char)
}
}
found := 0
// This time check id we're an A, and then check for pairs in the corners
for pos, letter := range board {
if letter != "A" {
continue
}
up_slash := board[pos.Move(utils.DownLeft, 1)] + letter + board[pos.Move(utils.UpRight, 1)]
if !(up_slash == "MAS" || up_slash == "SAM") {
continue
}
down_slash := board[pos.Move(utils.DownRight, 1)] + letter + board[pos.Move(utils.UpLeft, 1)]
if !(down_slash == "MAS" || down_slash == "SAM") {
continue
}
found++
}
fmt.Println(found)
}
func main() {
input := utils.ReadInput("input.txt")
part1(input)
part2(input)
}