-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (82 loc) · 1.74 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
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"errors"
"fmt"
"github.com/code-shoily/aocgo/gen"
"github.com/code-shoily/aocgo/year15"
"github.com/code-shoily/aocgo/year16"
"github.com/code-shoily/aocgo/year17"
"github.com/code-shoily/aocgo/year18"
"github.com/code-shoily/aocgo/year19"
"github.com/code-shoily/aocgo/year20"
"github.com/code-shoily/aocgo/year21"
"github.com/code-shoily/aocgo/year22"
"github.com/code-shoily/aocgo/year23"
"os"
"strconv"
)
const currentYear = 2023
func validate(year, day int) error {
if year < 2015 || year > currentYear {
return errors.New("invalid year entered")
}
if day < 1 || day > 25 {
return errors.New("invalid date entered")
}
return nil
}
func solve(year, day int) {
switch year {
case 2015:
year15.SolveForDay(day)
case 2016:
year16.SolveForDay(day)
case 2017:
year17.SolveForDay(day)
case 2018:
year18.SolveForDay(day)
case 2019:
year19.SolveForDay(day)
case 2020:
year20.SolveForDay(day)
case 2021:
year21.SolveForDay(day)
case 2022:
year22.SolveForDay(day)
case 2023:
year23.SolveForDay(day)
}
}
func extractFromArgs(args []string) (cmd string, year int, day int) {
if yearInt, error := strconv.Atoi(args[1]); error == nil {
year = yearInt
}
if dayInt, error := strconv.Atoi(args[2]); error == nil {
day = dayInt
}
return args[0], year, day
}
func main() {
args := os.Args
var (
cmd string
year, day int
)
if len(args) == 4 {
cmd, year, day = extractFromArgs(args[1:])
} else {
fmt.Println("[Usage] <cmd> <year> <day>")
os.Exit(1)
}
if error := validate(year, day); error != nil {
fmt.Println(error.Error())
os.Exit(1)
} else {
switch cmd {
case "gen", "g":
gen.GenerateSources(year, day)
case "solve", "run", "s", "r":
solve(year, day)
}
}
}