Skip to content

Commit 9aef291

Browse files
committed
Solved day22 part 2
1 parent ca7111f commit 9aef291

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2023'
7-
version '0.21.3'
7+
version '0.21.4'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day22/src/main/kotlin/de/havox_design/aoc2023/day22/Day22.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class Day22(private var filename: String) {
2222
return results!!.second
2323
}
2424

25+
@SuppressWarnings("kotlin:S3776")
2526
private fun calculateResults() {
26-
if(results != null) {
27+
if (results != null) {
2728
return
2829
}
2930

@@ -53,6 +54,7 @@ class Day22(private var filename: String) {
5354
}
5455

5556
var countToBeAbleToBeDisintegrated = 0L
57+
var countCollapsingBricks = 0L
5658

5759
for (i in 0..<bricks.size) {
5860
val save = bricks[i]
@@ -63,12 +65,26 @@ class Day22(private var filename: String) {
6365

6466
if (bricks.all { !it.canFall }) {
6567
countToBeAbleToBeDisintegrated++
68+
} else {
69+
val fallen = ArrayList(bricks)
70+
71+
for (j in (i + 1)..<fallen.size) {
72+
when {
73+
fallen[j].canFall(fallen) -> {
74+
countCollapsingBricks++
75+
76+
while (fallen[j].canFall(fallen)) {
77+
fallen[j] = fallen[j].fallen
78+
}
79+
}
80+
}
81+
}
6682
}
6783

6884
bricks[i] = save
6985
}
7086

71-
Pair(countToBeAbleToBeDisintegrated, 7L)
87+
results = Pair(countToBeAbleToBeDisintegrated, countCollapsingBricks)
7288
}
7389

7490
private fun getResourceAsText(path: String): List<String> =

0 commit comments

Comments
 (0)