Skip to content

Commit c9cd84c

Browse files
committed
Cleanup solution 2025-12 (Christmas Tree Farm)
Just a bit of code cleanup. No functional changes.
1 parent e220947 commit c9cd84c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/main/kotlin/de/ronny_h/aoc/year2025/day12/ChristmasTreeFarm.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@ class ChristmasTreeFarm : AdventOfCode<Int>(2025, 12) {
1212
return presents.regions.count { PresentsSpace(it, presents.shapes).allShapesFit() }
1313
}
1414

15-
override fun part2(input: List<String>): Int {
16-
return 0
17-
}
15+
override fun part2(input: List<String>): Int = 0
1816
}
1917

2018
fun List<String>.parsePresents(): Presents {
2119
val chunks = split()
22-
val shapes = chunks.dropLast(1).map { it.parseShape() }
23-
val regions = chunks.last().map { it.parseRegion() }
20+
val shapes = chunks.dropLast(1).map(List<String>::parseShape)
21+
val regions = chunks.last().map(String::parseRegion)
2422
return Presents(shapes, regions)
2523
}
2624

25+
// 0:
26+
// ###
27+
// ##.
28+
// ##.
2729
private fun List<String>.parseShape() = PresentShape(
2830
index = first().dropLast(1).toInt(),
2931
input = drop(1),
3032
)
3133

34+
// 4x4: 0 0 0 0 2 0
3235
private fun String.parseRegion(): Region {
3336
val (dimensions, presents) = split(": ")
3437
val (width, length) = dimensions.split("x").map(String::toInt)
@@ -63,12 +66,11 @@ class PresentShape(private val index: Int, input: List<String>) : SimpleCharGrid
6366

6467
class PresentsSpace(private val region: Region, private val shapes: List<PresentShape>) {
6568

66-
fun allShapesFit(): Boolean {
67-
val presentsToAdd = region.presents.mapIndexed { i, times ->
68-
if (times == 0) null else shapes[i] to times
69-
}.filterNotNull()
70-
71-
return presentsToAdd.sumOf { (shape, times) -> times * shape.numberOfTiles } <= region.area
72-
}
69+
// Note that this is just an approximation producing an upper bound.
70+
// Luckily this is enough to solve this year's last puzzle.
71+
fun allShapesFit(): Boolean = region
72+
.presents
73+
.mapIndexed { i, times -> shapes[i] to times }
74+
.sumOf { (shape, times) -> shape.numberOfTiles * times } <= region.area
7375

7476
}

0 commit comments

Comments
 (0)