-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (65 loc) · 1.64 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
package main
import (
"context"
"flag"
"fmt"
"time"
"github.com/fatih/color"
"github.com/friedemannf/advent_of_code/day"
"github.com/friedemannf/advent_of_code/util"
_ "github.com/friedemannf/advent_of_code/2023"
)
var (
file = flag.String("file", "input.txt", "input file")
d = flag.Int("day", -1, "day to run")
y = flag.Int("year", time.Now().Year(), "year to run")
part = flag.Int("part", 1, "part to run")
iteration = flag.Int("i", 0, "iteration to run")
benchmark = flag.Int("bench", 1, "benchmark iterations")
debug = flag.Bool("debug", false, "debug output")
)
func main() {
yellow := color.New(color.FgYellow).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
flag.Parse()
color.Red("Advent of Code 2023")
if *d == -1 {
*d = time.Now().Day()
}
// Read the input file.
fmt.Printf("Reading input file %s\n", yellow(*file))
lines, err := util.ReadLines(*file)
if err != nil {
panic(err)
}
fmt.Println("Year", yellow(*y))
fmt.Println("Day", yellow(*d))
d, ok := day.GetDay(*y, *d)
if !ok {
panic("day not found")
}
fmt.Println("Part", yellow(*part))
fmt.Println("Iteration", yellow(*iteration))
var s day.Solution
switch *part {
case 1:
s = d.Solution1[*iteration]
case 2:
s = d.Solution2[*iteration]
}
start := time.Now()
var res any
for i := 0; i < *benchmark; i++ {
res, err = s(day.Context{
Context: context.Background(),
Debug: *debug,
}, lines)
}
dur := time.Now().Sub(start)
if err != nil {
panic(err)
}
dur = time.Duration(dur.Nanoseconds() / int64(*benchmark))
fmt.Printf("Result: %v\n", green(res))
color.HiBlack("Took: %s\n", dur)
}