Skip to content

Commit

Permalink
2024 - Day 06 - part 2 now using parallelStream to speed up.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 6, 2024
1 parent c8a085c commit af98fde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/main/kotlin/no/rodland/advent_2024/Day06.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ class Day06(val input: List<String>) : Day<Int, Int, Pair<Pos, Array<CharArray>>

override fun partTwo(): Int {
val obstructions = doTheWalk()!!.map { it.first }.toSet() - start
return obstructions.map { check ->
doTheWalk { g: Grid, p: Pos -> if (p == check) '#' else g[p] }
}.count { it == null }
return obstructions
.parallelStream()
.map { check ->
doTheWalk { g: Grid, p: Pos -> if (p == check) '#' else g[p] }
}
.filter { it == null }
.count().toInt()
}

private fun doTheWalk(getter: (g: Grid, p: Pos) -> Char = { g, p -> g[p] }): MutableSet<Pair<Pos, Direction>>? {
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/no/rodland/advent_2024/Day06Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal class Day06Test {
resultTwo,
{ Day06(data06) },
{ Day06(test06) },
numTestPart1 = 10,
numTestPart2 = 1
)

Expand Down Expand Up @@ -63,7 +64,6 @@ internal class Day06Test {
}

@Test
@Slow(520)
fun `06,1,live,1`() {
report(test.livePart1)
}
Expand All @@ -77,7 +77,6 @@ internal class Day06Test {
}

@Test
@Slow(1200)
fun `06,2,live,1`() {
report(test.livePart2)
}
Expand Down

0 comments on commit af98fde

Please sign in to comment.