return early if total exceeds target

re-run benchmarks
This commit is contained in:
2024-12-07 23:47:20 +00:00
parent d42df0cd84
commit 9bfd45aee4
5 changed files with 22 additions and 14 deletions

View File

@@ -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

View File

@@ -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)