File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
src/main/kotlin/me/peckb/aoc/_2025/calendar/day07 Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -52,17 +52,18 @@ class Day07 @Inject constructor(
5252 val line = manifold[depth]
5353
5454 beams.toList().also { beams.clear() }.forEach { (location, count) ->
55- if (location.depth != depth - 1 ) { throw IllegalStateException (" We should only be tracking the last row." ) }
55+ if (location.depth != depth - 1 ) {
56+ throw IllegalStateException (" We should only be tracking the last row." )
57+ }
5658
57- if (line[ location.index] == ' ^ ' ) {
58- val left = Location (depth, location. index - 1 )
59- val right = Location (depth, location.index + 1 )
59+ // if we need to split then the indices of our location need to shift and split
60+ // otherwise we just stay at the same index we're at
61+ val indexDeltas = if (line[ location.index] == ' ^ ' ) listOf ( - 1 , 1 ) else listOf ( 0 )
6062
61- beams[left] = beams.getValue(left) + count
62- beams[right] = beams.getValue(right) + count
63- } else {
64- val below = Location (depth, location.index)
65- beams[below] = beams.getValue(below) + count
63+ indexDeltas.forEach { delta ->
64+ Location (depth, location.index + delta).let { loc ->
65+ beams[loc] = beams.getValue(loc) + count
66+ }
6667 }
6768 }
6869
You can’t perform that action at this time.
0 commit comments