From 67a04b91c8244c910878a1429d8f2fb03eef55a0 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 2 Dec 2024 18:30:26 +0000 Subject: [PATCH] remove log.Fatal's from solve.go, return values back to main. --- day-01/cmd/cli/main.go | 7 ++++++- day-01/solve.go | 19 ++++++++----------- day-01/solve_internal_test.go | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/day-01/cmd/cli/main.go b/day-01/cmd/cli/main.go index 428ce96..ff122ab 100644 --- a/day-01/cmd/cli/main.go +++ b/day-01/cmd/cli/main.go @@ -25,5 +25,10 @@ func main() { log.Fatal(err) } - problems.Solve(data) + one, two, err := problems.Solve(data) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("solution one: %d\nsolution two: %d\n", one, two) } diff --git a/day-01/solve.go b/day-01/solve.go index 39d0613..9825d8d 100644 --- a/day-01/solve.go +++ b/day-01/solve.go @@ -1,23 +1,20 @@ -package day01 +package dayone import ( - "fmt" - "log" - "github.com/onyx-and-iris/aoc2024/day-01/internal/one" "github.com/onyx-and-iris/aoc2024/day-01/internal/two" ) -func Solve(data []byte) { - val, err := one.Solve(data) +func Solve(data []byte) (int, int, error) { + answerOne, err := one.Solve(data) if err != nil { - log.Fatal(err) + return 0, 0, err } - fmt.Printf("solution one: %d\n", val) - val, err = two.Solve(data) + answerTwo, err := two.Solve(data) if err != nil { - log.Fatal(err) + return 0, 0, err } - fmt.Printf("solution two: %d\n", val) + + return answerOne, answerTwo, nil } diff --git a/day-01/solve_internal_test.go b/day-01/solve_internal_test.go index 151cb6f..1c00798 100644 --- a/day-01/solve_internal_test.go +++ b/day-01/solve_internal_test.go @@ -1,4 +1,4 @@ -package day01 +package dayone import ( _ "embed"