From e67369041e24014d08ad888f3556c28e1fa3ec29 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 5 Dec 2024 18:24:29 +0000 Subject: [PATCH] upd scaffold --- scaffold.sh | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/scaffold.sh b/scaffold.sh index dc26ac6..6168e3a 100755 --- a/scaffold.sh +++ b/scaffold.sh @@ -57,14 +57,135 @@ func main() { EOT touch "$name"/solve.go -cat <> "$name"/makefile +cat <> "$name"/solve.go package name +import ( + "github.com/onyx-and-iris/aoc2024/day-$1/internal/one" + "github.com/onyx-and-iris/aoc2024/day-$1/internal/two" +) + func Solve(data []byte) (int, int, error) { - return 0, 0, nil + answerOne, err := one.Solve(data) + if err != nil { + return 0, 0, err + } + + answerTwo, err := two.Solve(data) + if err != nil { + return 0, 0, err + } + + return answerOne, answerTwo, nil } EOT +touch "$name"/internal/one/solve.go +cat <> "$name"/internal/one/solve.go +package one + +import ( + "bufio" + "bytes" + "io" +) + +func Solve(data []byte) (int, error) { + r := bytes.NewReader(data) + err := parseLines(r) + if err != nil { + return 0, err + } + + return 0, nil +} + +func parseLines(r io.Reader) error { + scanner := bufio.NewScanner(r) + for scanner.Scan() { + } + + if err := scanner.Err(); err != nil { + return err + } + + return nil +} +EOT + +touch "$name"/internal/one/solve_internal_test.go +cat <> "$name"/internal/one/solve_internal_test.go +package one + +import ( + _ "embed" + "os" + "testing" +) + +//go:embed testdata/input.txt +var data []byte + +func BenchmarkSolve(b *testing.B) { + os.Stdout, _ = os.Open(os.DevNull) + Solve(data) +} +EOT + + +touch "$name"/internal/two/solve.go +cat <> "$name"/internal/two/solve.go +package two + +import ( + "bufio" + "bytes" + "io" +) + +func Solve(data []byte) (int, error) { + r := bytes.NewReader(data) + err := parseLines(r) + if err != nil { + return 0, err + } + + return 0, nil +} + +func parseLines(r io.Reader) error { + scanner := bufio.NewScanner(r) + for scanner.Scan() { + } + + if err := scanner.Err(); err != nil { + return err + } + + return nil +} +EOT + +touch "$name"/internal/two/solve_internal_test.go +cat <> "$name"/internal/two/solve_internal_test.go +package two + +import ( + _ "embed" + "os" + "testing" +) + +//go:embed testdata/input.txt +var data []byte + +func BenchmarkSolve(b *testing.B) { + os.Stdout, _ = os.Open(os.DevNull) + Solve(data) +} +EOT + + cd "$name" || exit go mod init github.com/onyx-and-iris/aoc2024/"$name"