-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (40 loc) · 869 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
package main
import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"reflect"
"strconv"
)
type Aoc struct{}
func Invoke(name string, args ...interface{}) {
aoc := Aoc{}
inputs := make([]reflect.Value, len(args))
for i := range args {
inputs[i] = reflect.ValueOf(args[i])
}
reflect.ValueOf(aoc).MethodByName(name).Call(inputs)
}
func main() {
files, _ := filepath.Glob("*.txt")
args := os.Args[1:]
dayno := int64(0)
for f := range files {
day, _ := strconv.ParseInt(files[f][3:len(files[f])-4], 10, 0)
if day > dayno {
dayno = day
}
}
if len(args) > 0 {
dayno, _ = strconv.ParseInt(args[0], 10, 0)
}
file, err := os.Open(fmt.Sprintf("day%d.txt", dayno))
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
Invoke(fmt.Sprintf("Day%d", dayno), scanner)
}