-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (43 loc) · 869 Bytes
/
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
package main
import (
dayPkg "AdventOfCode2024/day"
"fmt"
"io"
"os"
"strconv"
)
func main() {
args := os.Args
if len(args) < 3 {
fmt.Println("You must provide a day number and input file")
os.Exit(1)
}
dayNumber, err := strconv.Atoi(args[1])
if err != nil {
fmt.Println("Day must be a number")
os.Exit(1)
}
file, err := os.Open(args[2])
defer file.Close()
content, err := io.ReadAll(file)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
days := dayPkg.DaysList.FindByNumber(uint(dayNumber))
if len(days) == 0 {
fmt.Println("Error: Day not found")
os.Exit(1)
}
result := make([]string, len(days))
for i, day := range days {
result[i] = day.Run(string(content))
}
if len(result) == 1 {
fmt.Println(result[0])
} else {
for i, dayResult := range result {
fmt.Println("Part "+strconv.Itoa(i+1)+":", dayResult)
}
}
}