diff --git a/day-07/benchmark b/day-07/benchmark index 4e67d7a..1522938 100644 --- a/day-07/benchmark +++ b/day-07/benchmark @@ -2,14 +2,14 @@ goos: linux goarch: amd64 pkg: github.com/onyx-and-iris/aoc2024/day-07 cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz -BenchmarkSolve-12 1000000000 0.2486 ns/op -BenchmarkSolve-12 1000000000 0.2670 ns/op -BenchmarkSolve-12 1000000000 0.2498 ns/op -BenchmarkSolve-12 1000000000 0.2449 ns/op -BenchmarkSolve-12 1000000000 0.2520 ns/op -BenchmarkSolve-12 1000000000 0.2512 ns/op -BenchmarkSolve-12 1000000000 0.2500 ns/op -BenchmarkSolve-12 1000000000 0.2494 ns/op -BenchmarkSolve-12 1000000000 0.2473 ns/op -BenchmarkSolve-12 1000000000 0.2453 ns/op -ok github.com/onyx-and-iris/aoc2024/day-07 37.477s +BenchmarkSolve-12 1000000000 0.1503 ns/op +BenchmarkSolve-12 1000000000 0.1498 ns/op +BenchmarkSolve-12 1000000000 0.1577 ns/op +BenchmarkSolve-12 1000000000 0.1621 ns/op +BenchmarkSolve-12 1000000000 0.1490 ns/op +BenchmarkSolve-12 1000000000 0.1437 ns/op +BenchmarkSolve-12 1000000000 0.1566 ns/op +BenchmarkSolve-12 1000000000 0.1508 ns/op +BenchmarkSolve-12 1000000000 0.1465 ns/op +BenchmarkSolve-12 1000000000 0.1468 ns/op +ok github.com/onyx-and-iris/aoc2024/day-07 18.051s diff --git a/day-07/internal/one/benchmark b/day-07/internal/one/benchmark index cade16e..7335d04 100644 --- a/day-07/internal/one/benchmark +++ b/day-07/internal/one/benchmark @@ -2,5 +2,5 @@ goos: linux goarch: amd64 pkg: github.com/onyx-and-iris/aoc2024/day-07/internal/one cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz -BenchmarkSolve-12 1000000000 0.001456 ns/op +BenchmarkSolve-12 1000000000 0.001262 ns/op ok github.com/onyx-and-iris/aoc2024/day-07/internal/one 0.017s diff --git a/day-07/internal/one/solve.go b/day-07/internal/one/solve.go index 8b7af4c..06385e4 100644 --- a/day-07/internal/one/solve.go +++ b/day-07/internal/one/solve.go @@ -37,6 +37,10 @@ func Solve(buf []byte) (int, error) { } func next(target int, operands []int, total int, operator string) (int, bool) { + if total > target { + return 0, false + } + if len(operands) == 0 { if total == target { log.Debug(total) diff --git a/day-07/internal/two/benchmark b/day-07/internal/two/benchmark index 0172ba8..b8a35a2 100644 --- a/day-07/internal/two/benchmark +++ b/day-07/internal/two/benchmark @@ -2,5 +2,5 @@ goos: linux goarch: amd64 pkg: github.com/onyx-and-iris/aoc2024/day-07/internal/two cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz -BenchmarkSolve-12 1000000000 0.2539 ns/op -ok github.com/onyx-and-iris/aoc2024/day-07/internal/two 3.822s +BenchmarkSolve-12 1000000000 0.1525 ns/op +ok github.com/onyx-and-iris/aoc2024/day-07/internal/two 1.642s diff --git a/day-07/internal/two/solve.go b/day-07/internal/two/solve.go index 642cde5..5a27e03 100644 --- a/day-07/internal/two/solve.go +++ b/day-07/internal/two/solve.go @@ -38,6 +38,10 @@ func Solve(buf []byte) (int, error) { } func next(target int, operands []int, total int, operator string) (int, bool) { + if total > target { + return 0, false + } + if len(operands) == 0 { if total == target { log.Debug(total)