-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (49 loc) · 1.22 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
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/naruto678/aoc-go/globals"
_ "github.com/naruto678/aoc-go/register"
)
type AOC struct {
log *log.Logger
}
func main() {
day := flag.Int("day", -1, "day to run this code for ")
test := flag.Bool("test", false, "should this run for test input for real input")
flag.Parse()
if *day == -1 {
panic(fmt.Sprintf("day %d does not exist", *day))
}
var file_name string
if *test {
file_name = "test.txt"
} else {
file_name = "input.txt"
}
wd, _ := os.Getwd()
full_path := strings.Join([]string{wd, "days", fmt.Sprintf("day%d", *day), file_name}, string(os.PathSeparator))
if _, err := os.Stat(full_path); err == nil {
content, err := os.ReadFile(full_path)
if err != nil {
panic(err)
}
computeFirst(content, *day)
computeSecond(content, *day)
} else {
panic(err)
}
}
func computeFirst(content []byte, day int) {
fmt.Println(fmt.Sprintf("running the first part for day %d", day))
stub := globals.FuncMap[fmt.Sprintf("%d-%d", day, 1)]
stub(content)
}
func computeSecond(content []byte, day int) {
fmt.Println(fmt.Sprintf("running the second part for day %d", day))
stub := globals.FuncMap[fmt.Sprintf("%d-%d", day, 2)]
stub(content)
}