File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
day22/src/main/kotlin/de/havox_design/aoc2023/day22 Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ plugins {
44
55// project meta data
66group ' de.havox_design.aoc2023'
7- version ' 0.21.3 '
7+ version ' 0.21.4 '
88
99// Switch to gradle "all" distribution.
1010wrapper {
Original file line number Diff line number Diff 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 > =
You can’t perform that action at this time.
0 commit comments