From 3eb7e88d8bf80925d55f6de3167b0a3255a99073 Mon Sep 17 00:00:00 2001 From: Alexander Avery Date: Sun, 3 Dec 2023 00:26:27 -0500 Subject: [PATCH] add day 2 to main.go and simplify input reading --- main.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 747307c..0c83c3a 100644 --- a/main.go +++ b/main.go @@ -21,35 +21,28 @@ var ( // slice of all puzzles puzzles = []puzzle{ &day01{}, + &day02{}, } ) -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])) + path1 := fmt.Sprintf("input/%d-1", puzzleIndex) + path2 := fmt.Sprintf("input/%d-2", puzzleIndex) + + f1, err := os.Open(path1) + if err == nil { + fmt.Fprintf(os.Stdout, "Solution 1:\n%s\n", puzzle.solve1(f1)) + } + f2, err := os.Open(path2) + if err == nil { + fmt.Fprintf(os.Stdout, "Solution 2:\n%s\n", puzzle.solve2(f2)) + } }