Skip to content

Commit 9c8f222

Browse files
committed
[2025/11] Reactor (Part 2)
1 parent 4790e60 commit 9c8f222

4 files changed

Lines changed: 56 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
| 2022 |||||||||||||| | | | | | | || | | || 28 |
3030
| 2023 |||||||| | | | | | | | | | | | | | | | | | | 12 |
3131
| 2024 ||||||||||||||| |||||| || | || 40 |
32-
| 2025 |||||||||| | | |||||||||||||| 19 |
32+
| 2025 |||||||||| | | |||||||||||||| 20 |
3333

3434
## 🛷 How to run
3535

@@ -215,7 +215,7 @@ e.g. `HandyHaversacks`)*
215215
| | 7 | [Laboratories](https://adventofcode.com/2025/day/7) | [[Code](src/main/kotlin/adventofcode/year2025/Day07Laboratories.kt)] [[Test](src/test/kotlin/adventofcode/year2025/Day07LaboratoriesSpec.kt)] | `1711` | `36706966158365` |
216216
| | 8 | [Playground](https://adventofcode.com/2025/day/8) | [[Code](src/main/kotlin/adventofcode/year2025/Day08Playground.kt)] [[Test](src/test/kotlin/adventofcode/year2025/Day08PlaygroundSpec.kt)] | `135169` | `302133440` |
217217
| | 9 | [Movie Theater](https://adventofcode.com/2025/day/9) | [[Code](src/main/kotlin/adventofcode/year2025/Day09MovieTheater.kt)] [[Test](src/test/kotlin/adventofcode/year2025/Day09MovieTheaterSpec.kt)] | `4777409595` | `1473551379` |
218-
| | 11 | [Reactor](https://adventofcode.com/2025/day/11) | [[Code](src/main/kotlin/adventofcode/year2025/Day11Reactor.kt)] [[Test](src/test/kotlin/adventofcode/year2025/Day11ReactorSpec.kt)] | `699` | |
218+
| | 11 | [Reactor](https://adventofcode.com/2025/day/11) | [[Code](src/main/kotlin/adventofcode/year2025/Day11Reactor.kt)] [[Test](src/test/kotlin/adventofcode/year2025/Day11ReactorSpec.kt)] | `699` | `388893655378800` |
219219

220220
## 🕯️ Useful commands
221221

src/main/kotlin/adventofcode/year2025/Day11Reactor.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package adventofcode.year2025
33
import adventofcode.Puzzle
44
import adventofcode.PuzzleInput
55

6+
private typealias Device = String
7+
68
class Day11Reactor(
79
customInput: PuzzleInput? = null,
810
) : Puzzle(customInput) {
@@ -12,16 +14,28 @@ class Day11Reactor(
1214
.map { line -> line.split(": ", limit = 2) }
1315
.associate { (fromDevice, toDevices) -> Pair(fromDevice, toDevices.split(" ").toSet()) }
1416

15-
override fun partOne() = parseInput().countPaths(START)
17+
override fun partOne() = parseInput().countPaths(YOU)
18+
19+
override fun partTwo() = parseInput().countPaths(SVR, mustVisit = setOf(DAC, FFT))
1620

1721
companion object {
18-
private const val START = "you"
22+
private const val DAC = "dac"
1923
private const val END = "out"
24+
private const val FFT = "fft"
25+
private const val SVR = "svr"
26+
private const val YOU = "you"
2027

21-
private fun Map<String, Set<String>>.countPaths(device: String): Long =
22-
when (device) {
23-
END -> 1
24-
else -> this.getValue(device).sumOf { next -> countPaths(next) }
28+
private fun Map<Device, Set<Device>>.countPaths(
29+
device: Device,
30+
pathCounts: HashMap<Pair<Device, Set<Device>>, Long> = hashMapOf(),
31+
mustVisit: Set<Device> = emptySet(),
32+
): Long =
33+
pathCounts.getOrPut(Pair(device, mustVisit)) {
34+
when (device) {
35+
END if mustVisit.isEmpty() -> 1
36+
END -> 0
37+
else -> getValue(device).sumOf { next -> countPaths(next, pathCounts, mustVisit - device) }
38+
}
2539
}
2640
}
2741
}

src/test/kotlin/adventofcode/year2025/Day11ReactorSpec.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,37 @@ package adventofcode.year2025
22

33
import adventofcode.PuzzleBaseSpec
44

5-
class Day11ReactorSpec : PuzzleBaseSpec(5)
5+
class Day11ReactorSpec :
6+
PuzzleBaseSpec(
7+
listOf(
8+
"""
9+
aaa: you hhh
10+
you: bbb ccc
11+
bbb: ddd eee
12+
ccc: ddd eee fff
13+
ddd: ggg
14+
eee: out
15+
fff: out
16+
ggg: out
17+
hhh: ccc fff iii
18+
iii: out
19+
""".trimIndent() to 5,
20+
),
21+
listOf(
22+
"""
23+
svr: aaa bbb
24+
aaa: fft
25+
fft: ccc
26+
bbb: tty
27+
tty: ccc
28+
ccc: ddd eee
29+
ddd: hub
30+
hub: fff
31+
eee: dac
32+
dac: fff
33+
fff: ggg hhh
34+
ggg: out
35+
hhh: out
36+
""".trimIndent() to 2,
37+
),
38+
)

src/test/resources/inputs/year2025/day11.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)