107 lines
2.7 KiB
Go
107 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"aoc2015/day01"
|
|
"aoc2015/day02"
|
|
"aoc2015/day03"
|
|
"aoc2015/day04"
|
|
"aoc2015/day05"
|
|
"aoc2015/day06"
|
|
"aoc2015/day07"
|
|
"aoc2015/day08"
|
|
"aoc2015/day09"
|
|
"aoc2015/day10"
|
|
"aoc2015/day11"
|
|
"aoc2015/day12"
|
|
"aoc2015/day13"
|
|
"aoc2015/day14"
|
|
"aoc2015/day15"
|
|
"aoc2015/day16"
|
|
"aoc2015/day17"
|
|
"aoc2015/day18"
|
|
"aoc2015/day19"
|
|
"aoc2015/day20"
|
|
"aoc2015/day21"
|
|
"aoc2015/day22"
|
|
"aoc2015/day23"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"tools"
|
|
)
|
|
|
|
var dayFunctions map[int]map[int]func(puzzle tools.AoCPuzzle) interface{}
|
|
var day int
|
|
var part int
|
|
var test bool
|
|
var timeit bool
|
|
var timeitNumber int
|
|
var myDir, _ = filepath.Abs(filepath.Dir(os.Args[0]))
|
|
|
|
func initDayFunctions() {
|
|
dayFunctions = map[int]map[int]func(puzzle tools.AoCPuzzle) interface{}{
|
|
1: {1: day01.Part1, 2: day01.Part2},
|
|
2: {1: day02.Part1, 2: day02.Part2},
|
|
3: {1: day03.Part1, 2: day03.Part2},
|
|
4: {1: day04.Part1, 2: day04.Part2},
|
|
5: {1: day05.Part1, 2: day05.Part2},
|
|
6: {1: day06.Part1, 2: day06.Part2},
|
|
7: {1: day07.Part1, 2: day07.Part2},
|
|
8: {1: day08.Part1, 2: day08.Part2},
|
|
9: {1: day09.Part1, 2: day09.Part2},
|
|
10: {1: day10.Part1, 2: day10.Part2},
|
|
11: {1: day11.Part1, 2: day11.Part2},
|
|
12: {1: day12.Part1, 2: day12.Part2},
|
|
13: {1: day13.Part1, 2: day13.Part2},
|
|
14: {1: day14.Part1, 2: day14.Part2},
|
|
15: {1: day15.Part1, 2: day15.Part2},
|
|
16: {1: day16.Part1, 2: day16.Part2},
|
|
17: {1: day17.Part1, 2: day17.Part2},
|
|
18: {1: day18.Part1, 2: day18.Part2},
|
|
19: {1: day19.Part1, 2: day19.Part2},
|
|
20: {1: day20.Part1, 2: day20.Part2},
|
|
21: {1: day21.Part1, 2: day21.Part2},
|
|
22: {1: day22.Part1, 2: day22.Part2},
|
|
23: {1: day23.Part1, 2: day23.Part2},
|
|
}
|
|
}
|
|
|
|
func execute(thisDay int) {
|
|
p := tools.AoCPuzzle{}
|
|
if test {
|
|
p.FromFile = fmt.Sprintf("%s/inputs/%d_test", myDir, thisDay)
|
|
} else {
|
|
p.FromFile = fmt.Sprintf("%s/inputs/%d", myDir, thisDay)
|
|
}
|
|
p.ReadInputFromFile()
|
|
if part == -1 || part == 1 {
|
|
p.Solve(dayFunctions[thisDay][1], thisDay, 1, timeit, timeitNumber)
|
|
}
|
|
if part == -1 || part == 2 {
|
|
p.Solve(dayFunctions[thisDay][2], thisDay, 2, timeit, timeitNumber)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
initDayFunctions()
|
|
flag.IntVar(&day, "day", -1, "day to execute; -1 = all")
|
|
flag.IntVar(&part, "part", -1, "part to execute; -1 = all")
|
|
flag.BoolVar(&test, "test", false, "run the test case")
|
|
flag.BoolVar(&timeit, "timeit", false, "measure execution time")
|
|
flag.IntVar(&timeitNumber, "timeitNumber", 50, "build time average of this many runs")
|
|
flag.Parse()
|
|
|
|
if day != -1 {
|
|
if _, ok := dayFunctions[day]; !ok {
|
|
fmt.Printf("ERROR: unknown/invalid day: %d\n", day)
|
|
os.Exit(1)
|
|
}
|
|
execute(day)
|
|
} else {
|
|
for thisDay := range dayFunctions {
|
|
execute(thisDay)
|
|
}
|
|
}
|
|
}
|