File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
main/scala/eu/sim642/adventofcode2024
test/scala/eu/sim642/adventofcode2024 Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -24,25 +24,26 @@ object Day6 {
2424 def iterateGuard (input : Input ): Iterator [Guard ] =
2525 Iterator .iterate(input.guard)(stepGuard(input.grid))
2626
27- def countGuardPoss (input : Input ): Int = {
27+ def guardPoss (input : Input ): Set [ Pos ] = {
2828 iterateGuard(input)
2929 .takeWhile(guard => input.grid.containsPos(guard.pos))
3030 .map(_.pos)
3131 .toSet
32- .size
3332 }
3433
34+ def countGuardPoss (input : Input ): Int = guardPoss(input).size
35+
3536 def isGuardCycle (input : Input ): Boolean = {
3637 val it = iterateGuard(input).takeWhile(guard => input.grid.containsPos(guard.pos))
3738 val cycle = NaiveCycleFinder .find(it)
3839 cycle.isDefined
3940 }
4041
41- def countObstructionPoss (input : Input ): Int = { // TODO: optimize
42+ def countObstructionPoss (input : Input ): Int = { // TODO: optimize?
4243 val Input (grid, guard) = input
43- Box ( Pos .zero, Pos (grid( 8 ).size - 1 , grid.size - 1 ) )
44+ guardPoss(input )
4445 .iterator
45- .filter(obstructionPos => obstructionPos != guard.pos && ! grid(obstructionPos) )
46+ .filter(obstructionPos => obstructionPos != guard.pos)
4647 .map(obstructionPos => Input (grid.updatedGrid(obstructionPos, true ), guard))
4748 .count(isGuardCycle)
4849 }
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class Day6Test extends AnyFunSuite {
2929 assert(countObstructionPoss(parseInput(exampleInput)) == 6 )
3030 }
3131
32- ignore (" Part 2 input answer" ) {
33- assert(countObstructionPoss(parseInput(input)) == 1719 ) // TODO: optimize
32+ test (" Part 2 input answer" ) {
33+ assert(countObstructionPoss(parseInput(input)) == 1719 ) // TODO: optimize?
3434 }
3535}
You can’t perform that action at this time.
0 commit comments