-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
114 lines (94 loc) · 2.91 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
"github.com/WTFox/aoc2021/submarine"
"github.com/WTFox/aoc2021/util"
)
func main() {
Day08()
}
func Day08() {
inputs := util.ReadStringsFromFile("./inputs/day08-display.txt")
fmt.Println(submarine.DisplaySearch(inputs))
}
func Day07() {
inputString := util.ReadStringsFromFile("./inputs/day07-crabs-in-submarines.txt")[0]
crabSubmarines := util.StringToIntSlice(inputString)
fmt.Println(submarine.FindMostEfficientFuelUsage(crabSubmarines))
}
func Day06() {
fishesAsString := util.ReadStringsFromFile("./inputs/day06-lanternfish.txt")[0]
fishies := util.StringToIntSlice(fishesAsString)
fmt.Println(submarine.SimulateLanternFishLife(fishies, 256))
}
func Day05() {
inputs := util.ReadStringsFromFile("./inputs/day05.txt")
fmt.Println(submarine.SumVentOverlaps(inputs))
}
func Day04Part2() {
inputs := util.ReadStringsFromFile("./inputs/day04.txt")
bingoBoards := submarine.NewBingoMultiple(inputs)
fmt.Printf("%d boards\n", len(bingoBoards))
lastWinner := &bingoBoards[0]
for index := 0; index < len(bingoBoards); index++ {
bingo := &bingoBoards[index]
bingo.Play()
if bingo.HasBingo() {
score := bingo.Score()
if bingo.NumTurns > lastWinner.NumTurns {
fmt.Printf("Board %d won in %d moves with score %d.\n", index, bingo.NumTurns, score)
lastWinner = bingo
continue
}
}
}
fmt.Printf("Last board won in %d moves with score %d.\n", lastWinner.NumTurns, lastWinner.Score())
}
func Day04Part1() {
inputs := util.ReadStringsFromFile("./inputs/day04.txt")
bingoBoards := submarine.NewBingoMultiple(inputs)
fmt.Printf("%d boards\n", len(bingoBoards))
quickestWinner := &bingoBoards[0]
for index := 0; index < len(bingoBoards); index++ {
bingo := &bingoBoards[index]
bingo.Play()
if bingo.HasBingo() {
score := bingo.Score()
if bingo.NumTurns < quickestWinner.NumTurns {
fmt.Printf("Board %d won in %d moves with score %d.\n", index, bingo.NumTurns, score)
quickestWinner = bingo
continue
}
}
}
fmt.Printf("Quickest board won in %d moves with score %d.\n", quickestWinner.NumTurns, quickestWinner.Score())
}
func Day03() {
bytes := util.ReadStringsFromFile("./inputs/day03.txt")
d := submarine.NewDiagnosticReport(bytes)
d.Process()
fmt.Println(d.LifeSupportRating())
}
func Day02() {
instructions := util.ReadStringsFromFile("./inputs/day02.txt")
s := submarine.New()
s.ProcessInstructions(instructions)
fmt.Println(s.Result())
}
func Day01() {
depths := util.ReadIntegersFromFile("./inputs/day01.txt")
fmt.Println(countNumberOfPositiveChangesInDepth(depths))
}
func countNumberOfPositiveChangesInDepth(inputs []int) (result int) {
for index := 1; index < len(inputs); index++ {
if index+2 > len(inputs)-1 {
break
}
lastWindowSum := inputs[index-1] + inputs[index] + inputs[index+1]
currentWindowSum := inputs[index] + inputs[index+1] + inputs[index+2]
if lastWindowSum < currentWindowSum {
result++
}
}
return result
}