solutions for the Advent of Code 2023
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.

56 lines
948 B

12 months ago
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"strconv"
)
type puzzle interface {
solve1(r io.Reader) string
solve2(r io.Reader) string
12 months ago
}
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)
12 months ago
f1, err := os.Open(path1)
if err == nil {
inputs[0] = f1
12 months ago
}
f2, err := os.Open(path2)
if err == nil {
inputs[1] = f2
12 months ago
}
return inputs
}
func main() {
flag.Parse()
puzzleIndex, err := strconv.Atoi(*day)
12 months ago
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]))
12 months ago
}