-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (32 loc) · 772 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
package main
import (
"aoc-2024/common"
_ "aoc-2024/solvers" // Import the solutions package to trigger registration
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"strings"
)
func main() {
if len(os.Args) < 2 {
log.Fatalf("Usage: go run main.go <day>")
}
day := os.Args[1]
dayInt, err := strconv.Atoi(day)
if err != nil {
log.Fatalf("Invalid day: %v", day)
}
solver, exists := common.GetSolver(dayInt)
if !exists {
log.Fatalf("No solver for day %d", dayInt)
}
inputFile := filepath.Join("inputs", fmt.Sprintf("day%d.txt", dayInt))
input, err := os.ReadFile(inputFile)
if err != nil {
log.Fatalf("Failed to read input file: %v", err)
}
result := solver(strings.TrimSpace(string(input)))
fmt.Printf("Day %d result: %s\n", dayInt, result)
}