mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2026-04-07 01:23:34 +00:00
use endpoints map to keep score (size of map)
This commit is contained in:
@@ -2,5 +2,5 @@ goos: linux
|
||||
goarch: amd64
|
||||
pkg: github.com/onyx-and-iris/aoc2024/day-10/internal/one
|
||||
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
|
||||
BenchmarkSolve-12 1000000000 0.001398 ns/op
|
||||
ok github.com/onyx-and-iris/aoc2024/day-10/internal/one 0.014s
|
||||
BenchmarkSolve-12 1000000000 0.0008911 ns/op
|
||||
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)
|
||||
|
||||
var score int
|
||||
visited := make(map[point]struct{})
|
||||
endpoints := make(map[point]struct{})
|
||||
for !queue.IsEmpty() {
|
||||
current := queue.Dequeue()
|
||||
|
||||
_, ok := endpoints[current]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
endpoints[current] = struct{}{}
|
||||
|
||||
if graph.valueAt(current) == target {
|
||||
score++
|
||||
_, ok := endpoints[current]
|
||||
if !ok {
|
||||
endpoints[current] = struct{}{}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
_, ok = visited[current]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
visited[current] = struct{}{}
|
||||
|
||||
for _, n := range neighbours(current) {
|
||||
if graph.isOutOfBounds(n) {
|
||||
continue
|
||||
@@ -60,8 +49,8 @@ func Solve(buf []byte) (int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("score for trailhead %v - %d\n", pos, score)
|
||||
totalScore += score
|
||||
log.Debugf("score for trailhead %v - %d\n", pos, len(endpoints))
|
||||
totalScore += len(endpoints)
|
||||
}
|
||||
|
||||
return totalScore, nil
|
||||
|
||||
Reference in New Issue
Block a user