feat: add day 3 2024 (iter crashes on solution 2)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user