mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
use endpoints map to keep score (size of map)
This commit is contained in:
parent
2c3e68d884
commit
c12cc2c38e
@ -2,14 +2,14 @@ goos: linux
|
|||||||
goarch: amd64
|
goarch: amd64
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-10
|
pkg: github.com/onyx-and-iris/aoc2024/day-10
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||||
BenchmarkSolve-12 1000000000 0.002208 ns/op
|
BenchmarkSolve-12 1000000000 0.001775 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002135 ns/op
|
BenchmarkSolve-12 1000000000 0.001641 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002113 ns/op
|
BenchmarkSolve-12 1000000000 0.001804 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002273 ns/op
|
BenchmarkSolve-12 1000000000 0.001658 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002123 ns/op
|
BenchmarkSolve-12 1000000000 0.001679 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002133 ns/op
|
BenchmarkSolve-12 1000000000 0.001703 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002054 ns/op
|
BenchmarkSolve-12 1000000000 0.001641 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002107 ns/op
|
BenchmarkSolve-12 1000000000 0.001627 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002664 ns/op
|
BenchmarkSolve-12 1000000000 0.001654 ns/op
|
||||||
BenchmarkSolve-12 1000000000 0.002081 ns/op
|
BenchmarkSolve-12 1000000000 0.001719 ns/op
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-10 0.167s
|
ok github.com/onyx-and-iris/aoc2024/day-10 0.135s
|
||||||
|
@ -2,5 +2,5 @@ goos: linux
|
|||||||
goarch: amd64
|
goarch: amd64
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-10/internal/one
|
pkg: github.com/onyx-and-iris/aoc2024/day-10/internal/one
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||||
BenchmarkSolve-12 1000000000 0.001398 ns/op
|
BenchmarkSolve-12 1000000000 0.0008911 ns/op
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-10/internal/one 0.014s
|
ok github.com/onyx-and-iris/aoc2024/day-10/internal/one 0.012s
|
||||||
|
@ -25,29 +25,18 @@ func Solve(buf []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
queue.Enqueue(pos)
|
queue.Enqueue(pos)
|
||||||
|
|
||||||
var score int
|
|
||||||
visited := make(map[point]struct{})
|
|
||||||
endpoints := make(map[point]struct{})
|
endpoints := make(map[point]struct{})
|
||||||
for !queue.IsEmpty() {
|
for !queue.IsEmpty() {
|
||||||
current := queue.Dequeue()
|
current := queue.Dequeue()
|
||||||
|
|
||||||
_, ok := endpoints[current]
|
|
||||||
if ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
endpoints[current] = struct{}{}
|
|
||||||
|
|
||||||
if graph.valueAt(current) == target {
|
if graph.valueAt(current) == target {
|
||||||
score++
|
_, ok := endpoints[current]
|
||||||
|
if !ok {
|
||||||
|
endpoints[current] = struct{}{}
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok = visited[current]
|
|
||||||
if ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
visited[current] = struct{}{}
|
|
||||||
|
|
||||||
for _, n := range neighbours(current) {
|
for _, n := range neighbours(current) {
|
||||||
if graph.isOutOfBounds(n) {
|
if graph.isOutOfBounds(n) {
|
||||||
continue
|
continue
|
||||||
@ -60,8 +49,8 @@ func Solve(buf []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("score for trailhead %v - %d\n", pos, score)
|
log.Debugf("score for trailhead %v - %d\n", pos, len(endpoints))
|
||||||
totalScore += score
|
totalScore += len(endpoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalScore, nil
|
return totalScore, nil
|
||||||
|
@ -2,5 +2,5 @@ goos: linux
|
|||||||
goarch: amd64
|
goarch: amd64
|
||||||
pkg: github.com/onyx-and-iris/aoc2024/day-10/internal/two
|
pkg: github.com/onyx-and-iris/aoc2024/day-10/internal/two
|
||||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||||
BenchmarkSolve-12 1000000000 0.0009003 ns/op
|
BenchmarkSolve-12 1000000000 0.0008468 ns/op
|
||||||
ok github.com/onyx-and-iris/aoc2024/day-10/internal/two 0.012s
|
ok github.com/onyx-and-iris/aoc2024/day-10/internal/two 0.011s
|
||||||
|
Loading…
Reference in New Issue
Block a user