Skip to content

Commit ca7111f

Browse files
committed
Added day22 part 2
1 parent 102cb80 commit ca7111f

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
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.2'
7+
version '0.21.3'
88

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

day22/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ So, in this example, **`5`** bricks can be safely disintegrated.
136136

137137
Figure how the blocks will settle based on the snapshot. Once they've settled, consider disintegrating a single brick;
138138
**how many bricks could be safely chosen as the one to get disintegrated**?
139+
140+
# Part Two
141+
Disintegrating bricks one at a time isn't going to be fast enough. While it might sound dangerous, what you really need
142+
is a **chain reaction**.
143+
144+
You'll need to figure out the best brick to disintegrate. For each brick, determine how many **other bricks would fall**
145+
if that brick were disintegrated.
146+
147+
Using the same example as above:
148+
* Disintegrating brick `A` would cause all **`6`** other bricks to fall.
149+
* Disintegrating brick `F` would cause only **`1`** other brick, `G`, to fall.
150+
151+
Disintegrating any other brick would cause **no other bricks** to fall. So, in this example, the sum of **the number of
152+
other bricks that would fall** as a result of disintegrating each brick is **`7`**.
153+
154+
For each brick, determine how many **other bricks** would fall if that brick were disintegrated. **What is the sum of
155+
the number of other bricks that would fall**?

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,23 @@ class Day22(private var filename: String) {
1010

1111
private val number = Regex("-?\\d+")
1212

13+
private var results: Pair<Long, Long>? = null
14+
1315
fun solvePart1(): Long {
16+
calculateResults()
17+
return results!!.first
18+
}
19+
20+
fun solvePart2(): Long {
21+
calculateResults()
22+
return results!!.second
23+
}
24+
25+
private fun calculateResults() {
26+
if(results != null) {
27+
return
28+
}
29+
1430
bricks.clear()
1531

1632
for (row in getResourceAsText(filename)) {
@@ -52,12 +68,9 @@ class Day22(private var filename: String) {
5268
bricks[i] = save
5369
}
5470

55-
return countToBeAbleToBeDisintegrated
71+
Pair(countToBeAbleToBeDisintegrated, 7L)
5672
}
5773

58-
fun solvePart2(): Long =
59-
0L
60-
6174
private fun getResourceAsText(path: String): List<String> =
6275
this.javaClass.classLoader.getResourceAsStream(path)!!.bufferedReader().readLines()
6376

day22/src/test/kotlin/de/havox_design/aoc2023/day22/Day22Test.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Day22Test {
3333
@JvmStatic
3434
private fun getDataForTestSolvePart2(): Stream<Arguments> =
3535
Stream.of(
36-
Arguments.of("part2sample1.txt", 0L)
36+
Arguments.of("part1sample.txt", 7L)
3737
)
3838
}
3939
}

0 commit comments

Comments
 (0)