|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type puzzle interface {
|
|
|
|
solve1(r io.Reader) string
|
|
|
|
solve2(r io.Reader) string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// pick which day to run with a flag
|
|
|
|
day = flag.String("d", "", "which day to solve")
|
|
|
|
|
|
|
|
// slice of all puzzles
|
|
|
|
puzzles = []puzzle{
|
|
|
|
&day01{},
|
|
|
|
&day02{},
|
|
|
|
&day03{},
|
|
|
|
&day04{},
|
|
|
|
&day05{},
|
|
|
|
&day06{},
|
|
|
|
&day07{},
|
|
|
|
&day08{},
|
|
|
|
&day09{},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
puzzleIndex, err := strconv.Atoi(*day)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("invalid puzzle day: %s", *day)
|
|
|
|
}
|
|
|
|
|
|
|
|
puzzle := puzzles[puzzleIndex-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))
|
|
|
|
}
|
|
|
|
}
|