-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (45 loc) · 933 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
52
53
54
55
56
57
58
package main
import (
"fmt"
"io"
"os"
"strconv"
"github.com/brpratt/aoc2022/day01"
"github.com/brpratt/aoc2022/day02"
"github.com/brpratt/aoc2022/day03"
"github.com/brpratt/aoc2022/day04"
)
type Solution func(io.Reader) (string, string)
var solutions = []Solution{
day01.Solve,
day02.Solve,
day03.Solve,
day04.Solve,
}
func ExitWithUsage() {
fmt.Println("Usage: aoc2022 <day>\n\t<day>: number between 1 and 25, inclusive")
os.Exit(1)
}
func main() {
if len(os.Args) != 2 {
ExitWithUsage()
}
day, err := strconv.Atoi(os.Args[1])
if err != nil {
ExitWithUsage()
}
if day < 1 || day > 25 {
ExitWithUsage()
}
if day > len(solutions) {
fmt.Printf("No solution for day %02d\n", day)
os.Exit(1)
}
input, err := os.Open(fmt.Sprintf("day%02d/input.txt", day))
if err != nil {
panic(err)
}
defer input.Close()
part1, part2 := solutions[day-1](input)
fmt.Printf("%s\n%s\n", part1, part2)
}