feat: add day 3 2024 (iter crashes on solution 2)

This commit is contained in:
xuu
2024-12-03 14:51:54 -07:00
parent 2274eca981
commit 669e2cfb2c
6 changed files with 309 additions and 4 deletions
+9 -4
View File
@@ -4,6 +4,7 @@ import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"
@@ -16,7 +17,7 @@ import (
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
func runnerFile[R any, F func(*os.File) (R, error)]() *os.File {
if len(os.Args) < 2 {
Log("Usage:", filepath.Base(os.Args[0]), "FILE")
os.Exit(22)
@@ -57,16 +58,20 @@ func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
}()
}
input, err := os.Open(inputFilename)
if err != nil {
Log(err)
os.Exit(1)
}
scan := bufio.NewScanner(input)
return input
}
return run(scan)
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
return run(bufio.NewScanner(runnerFile[R]()))
}
func RunnerReader[R any, F func(io.Reader) (R, error)](run F) (R, error) {
return run(runnerFile[R]())
}
func MustResult[T any](result T, err error) {