Advent of Code Solutions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
715 B

package main
import (
adventoc2024 "adventoc/2024"
"bytes"
"flag"
"fmt"
"io"
"log"
"os"
"strconv"
)
type puzzle interface {
Part1(io.Reader) string
Part2(io.Reader) string
}
var puzzles = []puzzle{
adventoc2024.Day1{},
adventoc2024.Day2{},
}
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)
}
}
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))
}