package main import ( "flag" "fmt" "io" "log" "os" "strconv" ) type puzzle interface { solve1(r io.Reader) string solve2(r io.Reader) string } var ( // pick which day to run with a flag day = flag.String("d", "", "which day to solve") // slice of all puzzles puzzles = []puzzle{ &day01{}, } ) func inputs(day int) [2]io.Reader { inputs := [2]io.Reader{} path1 := fmt.Sprintf("input/%d-1", day) path2 := fmt.Sprintf("input/%d-2", day) f1, err := os.Open(path1) if err == nil { inputs[0] = f1 } f2, err := os.Open(path2) if err == nil { inputs[1] = f2 } return inputs } func main() { flag.Parse() puzzleIndex, err := strconv.Atoi(*day) if err != nil { log.Fatalf("invalid puzzle day: %s", *day) } inputs := inputs(puzzleIndex) puzzle := puzzles[puzzleIndex-1] fmt.Fprintf(os.Stdout, "Solution 1:\n%s\n", puzzle.solve1(inputs[0])) fmt.Fprintf(os.Stdout, "Solution 2:\n%s\n", puzzle.solve2(inputs[1])) }