Skip to content

Commit 2609e60

Browse files
committed
[2025/10] Factory (Part 1)
1 parent 9c8f222 commit 2609e60

File tree

5 files changed

+286
-1
lines changed

5 files changed

+286
-1
lines changed

README.md

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

3434
## 🛷 How to run
3535

@@ -215,6 +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+
| | 10 | [Factory](https://adventofcode.com/2025/day/10) | [[Code](src/main/kotlin/adventofcode/year2025/Day10Factory.kt)] [[Test](src/test/kotlin/adventofcode/year2025/Day10FactorySpec.kt)] | `517` | |
218219
| | 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` |
219220

220221
## 🕯️ Useful commands
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package adventofcode.year2025
2+
3+
import adventofcode.Puzzle
4+
import adventofcode.PuzzleInput
5+
import adventofcode.common.Permutations.powersets
6+
7+
class Day10Factory(
8+
customInput: PuzzleInput? = null,
9+
) : Puzzle(customInput) {
10+
private fun parseInput() = input.lines().map(Machine::invoke)
11+
12+
override fun partOne() =
13+
parseInput()
14+
.sumOf { machine ->
15+
machine
16+
.buttons
17+
.powersets()
18+
.sortedBy { combination -> combination.size }
19+
.first { combination ->
20+
combination.fold(List(machine.lights.size) { false }) { lights, buttons ->
21+
lights.mapIndexed { index, light ->
22+
when (index in buttons) {
23+
true -> !light
24+
else -> light
25+
}
26+
}
27+
} == machine.lights
28+
}.size
29+
}
30+
31+
companion object {
32+
private data class Machine(
33+
val lights: List<Boolean>,
34+
val buttons: List<List<Int>>,
35+
val joltages: List<Int>,
36+
) {
37+
companion object {
38+
operator fun invoke(input: String): Machine {
39+
val lights =
40+
input
41+
.substringAfter("[")
42+
.substringBefore("]")
43+
.split("")
44+
.filter(String::isNotEmpty)
45+
.map { light ->
46+
when (light.single()) {
47+
'#' -> true
48+
else -> false
49+
}
50+
}
51+
52+
val buttons =
53+
input
54+
.substringAfter(" ")
55+
.substringBefore(" {")
56+
.split(" ")
57+
.map { buttons ->
58+
buttons
59+
.replace("(", "")
60+
.replace(")", "")
61+
.split(",")
62+
.map(String::toInt)
63+
}
64+
65+
val joltages =
66+
input
67+
.substringAfter("{")
68+
.substringBefore("}")
69+
.split(",")
70+
.map(String::toInt)
71+
72+
return Machine(lights, buttons, joltages)
73+
}
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)