Browse Source

adjust puzzle runner

master
Alexander Avery 3 weeks ago
parent
commit
84139b2ed6
  1. 25
      main.go

25
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))
}

Loading…
Cancel
Save