@@ -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
2018fun 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+ // ##.
2729private 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
3235private 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
6467class 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