From 84139b2ed6736c75b1673c3e8be853021316e59c Mon Sep 17 00:00:00 2001 From: Alexander Avery Date: Tue, 3 Dec 2024 21:40:17 -0500 Subject: [PATCH] adjust puzzle runner --- main.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 7e9875f..b2d5ee6 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "io" "log" "os" - "strconv" ) type puzzle interface { @@ -16,32 +15,22 @@ type puzzle interface { Part2(io.Reader) string } -var puzzles = []puzzle{ - adventoc2024.Day1{}, - adventoc2024.Day2{}, +var puzzles = map[string]puzzle{ + "1": adventoc2024.Day1{}, + "2": adventoc2024.Day2{}, + "3": adventoc2024.Day3{}, } func main() { flag.Parse() - pi := 0 - if i := flag.Arg(0); i != "" { - var err error - pi, err = strconv.Atoi(i) - if err != nil { - log.Fatalf("invalid puzzle day: %s", i) - } - pi-- - - if pi < 0 || pi > len(puzzles) { - log.Fatalf("puzzle index %d is out of range", pi) - } + puzzle, ok := puzzles[flag.Arg(0)] + if !ok { + log.Fatalf("invalid puzzle day %s", flag.Arg(0)) } buf := new(bytes.Buffer) tee := io.TeeReader(os.Stdin, buf) - puzzle := puzzles[pi] - fmt.Println("Part 1:", puzzle.Part1(tee)) fmt.Println("Part 2:", puzzle.Part2(buf)) }