-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunner.go
64 lines (51 loc) · 1.36 KB
/
runner.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
package aoc
import (
"fmt"
"os"
"text/tabwriter"
internal "github.com/igorwulff/aoc/internal"
)
func Run() {
args := internal.ProcessArgs()
plugins, err := internal.GetProcessors(args)
if err != nil {
fmt.Println(err)
return
}
for _, p := range plugins {
input, err := p.GetInput()
if err != nil {
fmt.Printf("Could not find input.txt for Day %s Part %s\n", p.Args.Day, p.Args.Part)
return
}
fmt.Printf("Running day %s, part %s", p.Args.Day, p.Args.Part)
if err := p.Build(); err != nil {
fmt.Print("ERROR!\n", err)
return
}
if err := p.RunTests(); err != nil {
fmt.Print("ERROR!\n", err)
return
}
fmt.Println("Trying to solve puzzle...")
p.Benchmark.StartTimer()
output, err := p.CallFunc(input)
if err != nil {
fmt.Print("ERROR!\n", err)
return
}
p.Benchmark.StopTimer()
fmt.Printf("Solution: %s\n\n", output)
}
fmt.Println("Execution finished!")
w := tabwriter.NewWriter(os.Stdout, 0, 4, 4, ' ', 0)
fmt.Fprintln(w, "\nDay\tPart\tTime (ms)")
var sum float64 = 0.0
for _, p := range plugins {
sum += p.Benchmark.GetTotalTime()
// @TODO: would be nice to join day & parts in a single row, but for now it's already nice they're alphabetically sorted
fmt.Fprintf(w, "%s\t%s\t%8.3f\n", p.Args.Day, p.Args.Part, p.Benchmark.GetTotalTime())
}
w.Flush()
fmt.Printf("\nTotal time: %.3f ms\n", sum)
}