|
@ -8,7 +8,6 @@ import ( |
|
|
"io" |
|
|
"io" |
|
|
"log" |
|
|
"log" |
|
|
"os" |
|
|
"os" |
|
|
"strconv" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type puzzle interface { |
|
|
type puzzle interface { |
|
@ -16,32 +15,22 @@ type puzzle interface { |
|
|
Part2(io.Reader) string |
|
|
Part2(io.Reader) string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var puzzles = []puzzle{ |
|
|
var puzzles = map[string]puzzle{ |
|
|
adventoc2024.Day1{}, |
|
|
"1": adventoc2024.Day1{}, |
|
|
adventoc2024.Day2{}, |
|
|
"2": adventoc2024.Day2{}, |
|
|
|
|
|
"3": adventoc2024.Day3{}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
pi := 0 |
|
|
puzzle, ok := puzzles[flag.Arg(0)] |
|
|
if i := flag.Arg(0); i != "" { |
|
|
if !ok { |
|
|
var err error |
|
|
log.Fatalf("invalid puzzle day %s", flag.Arg(0)) |
|
|
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) |
|
|
buf := new(bytes.Buffer) |
|
|
tee := io.TeeReader(os.Stdin, buf) |
|
|
tee := io.TeeReader(os.Stdin, buf) |
|
|
|
|
|
|
|
|
puzzle := puzzles[pi] |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("Part 1:", puzzle.Part1(tee)) |
|
|
fmt.Println("Part 1:", puzzle.Part1(tee)) |
|
|
fmt.Println("Part 2:", puzzle.Part2(buf)) |
|
|
fmt.Println("Part 2:", puzzle.Part2(buf)) |
|
|
} |
|
|
} |
|
|