diff --git a/src/aoc2023/Day22.kt b/src/aoc2023/Day22.kt index 5acee1f..bb003ae 100644 --- a/src/aoc2023/Day22.kt +++ b/src/aoc2023/Day22.kt @@ -183,7 +183,7 @@ fun main() { } val disBricks = bricks.filterNot { it.onTopBricks.all { it.uponBricks.size != 1 } } val safeBricks = bricks.size - disBricks.size - var sum = 0 + var fallingSum = 0 for (brick in disBricks) { val fallingSet = HashSet() val removeQueue = ArrayDeque() @@ -192,11 +192,11 @@ fun main() { while (removeQueue.isNotEmpty()) { val falling = removeQueue.removeFirst() fallingSet.add(falling) - removeQueue.addAll(falling.onTopBricks.filter { it.uponBricks.subtract(fallingSet).isEmpty() }) + removeQueue.addAll(falling.onTopBricks.filter { fallingSet.containsAll(it.uponBricks) }) } - sum += fallingSet.size - 1 + fallingSum += fallingSet.size - 1 } - return safeBricks to sum + return safeBricks to fallingSum } // test if implementation meets criteria from the description, like: