chore: add day 9

This commit is contained in:
xuu 2023-12-09 10:52:49 -07:00
parent 1045fcba4c
commit b7e576729c
Signed by: xuu
GPG Key ID: 8B3B0604F164E04F

View File

@ -4,12 +4,13 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"os" "os"
"path/filepath"
"strings" "strings"
) )
func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) { func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
if len(os.Args) != 2 { if len(os.Args) != 2 {
Log("Usage:", os.Args[0], "FILE") Log("Usage:", filepath.Base(os.Args[0]), "FILE")
os.Exit(22) os.Exit(22)
} }
@ -23,6 +24,15 @@ func Runner[R any, F func(*bufio.Scanner) (R, error)](run F) (R, error) {
return run(scan) return run(scan)
} }
func MustResult[T any](result T, err error) {
if err != nil {
fmt.Println("ERR", err)
os.Exit(1)
}
Log("result", result)
}
func Log(v ...any) { fmt.Fprintln(os.Stderr, v...) } func Log(v ...any) { fmt.Fprintln(os.Stderr, v...) }
func Logf(format string, v ...any) { func Logf(format string, v ...any) {
if !strings.HasSuffix(format, "\n") { if !strings.HasSuffix(format, "\n") {