-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (84 loc) · 2.06 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
package main
import (
"advent-of-code-2023/code"
"bufio"
"fmt"
"log"
"os"
"strings"
)
func run_day(day int, input string) {
switch day {
case 1:
fmt.Println("Day 1: Trebuchet!?")
sum := code.Trebuchet_Part1(input)
fmt.Printf("Part 1 Answer: %d\n", sum)
sum = code.Trebuchet_Part2(input)
fmt.Printf("Part 2 Answer: %d\n", sum)
case 2:
fmt.Println("Day 2: Cube Conundrum")
sum, err := code.CubeConundrum_Part1(input, 12, 13, 14)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 1 Answer: %d\n", sum)
sum, err = code.CubeConundrum_Part2(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 2 Answer: %d\n", sum)
case 3:
fmt.Println("Day 3: Gear Ratios")
sum, err := code.GearRatios_Part1(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 1 Answer: %d\n", sum)
sum, err = code.GearRatios_Part2(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 2 Answer: %d\n", sum)
case 4:
fmt.Println("Day 4: Scratchcards")
sum, err := code.Scratchcards_Part1(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 1 Answer: %d\n", sum)
sum, err = code.Scratchcards_Part2(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 2 Answer: %d\n", sum)
case 5:
fmt.Println("Day 5: If You Give A Seed A Fertilizer")
sum, err := code.SeedFertilizer_Part1(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 1 Answer: %d\n", sum)
sum, err = code.SeedFertilizer_Part2(input)
if err != nil {
fmt.Printf("error: %d\n", err)
}
fmt.Printf("Part 2 Answer: %d\n", sum)
}
}
func main() {
days := []int{5}
for _, day := range days {
file, err := os.Open(fmt.Sprintf("day%v_input.txt", day))
if err != nil {
log.Fatal("unable to read input file")
}
defer file.Close()
scanner := bufio.NewScanner(file)
input := ""
for scanner.Scan() {
input += fmt.Sprintf("%s\n", strings.TrimSpace(scanner.Text()))
}
input = input[:len(input)-1]
run_day(day, input)
}
}