mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
clear up result zero value
use local count variable
This commit is contained in:
parent
1e2188db1a
commit
aafe39aa85
@ -25,23 +25,21 @@ func Solve(buf []byte) (int, error) {
|
|||||||
memo := make(map[int]result)
|
memo := make(map[int]result)
|
||||||
for range blinks {
|
for range blinks {
|
||||||
next := make(map[int]int)
|
next := make(map[int]int)
|
||||||
visited := make(map[int]int)
|
|
||||||
|
|
||||||
for stone, count := range old {
|
for stone, count := range old {
|
||||||
var r result
|
var r result
|
||||||
_, ok := visited[stone]
|
r, ok := memo[stone]
|
||||||
if !ok {
|
if !ok {
|
||||||
r = applyRules(stone)
|
r = applyRules(stone)
|
||||||
memo[stone] = r
|
memo[stone] = r
|
||||||
}
|
}
|
||||||
visited[stone] += count
|
|
||||||
|
|
||||||
switch r.kind {
|
switch r.kind {
|
||||||
case flip, multiply:
|
case flip, multiply:
|
||||||
next[r.right] += visited[stone]
|
next[r.right] += count
|
||||||
case split:
|
case split:
|
||||||
next[r.left] += visited[stone]
|
next[r.left] += count
|
||||||
next[r.right] += visited[stone]
|
next[r.right] += count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user