Skip to content

Commit a38dd16

Browse files
committed
[2025/12] Christmas Tree Farm (Part 1)
1 parent 975879f commit a38dd16

3 files changed

Lines changed: 1061 additions & 1 deletion

File tree

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 |||||||||||| |||||||||||||| 21 |
32+
| 2025 |||||||||||| |||||||||||||| 22 |
3333

3434
## 🛷 How to run
3535

@@ -217,6 +217,7 @@ e.g. `HandyHaversacks`)*
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` |
218218
| | 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` | |
219219
| | 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` |
220+
| | 12 | [Christmas Tree Farm](https://adventofcode.com/2025/day/12) | [[Code](src/main/kotlin/adventofcode/year2025/Day12ChristmasTreeFarm.kt)] | `524` | |
220221

221222
## 🕯️ Useful commands
222223

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package adventofcode.year2025
2+
3+
import adventofcode.Puzzle
4+
import adventofcode.PuzzleInput
5+
6+
private typealias TreeArea = Long
7+
private typealias Presents = List<Long>
8+
private typealias Tree = Pair<TreeArea, Presents>
9+
10+
class Day12ChristmasTreeFarm(
11+
customInput: PuzzleInput? = null,
12+
) : Puzzle(customInput) {
13+
private fun parseInput() =
14+
input
15+
.substringAfterLast("\n\n")
16+
.lines()
17+
.map { line -> line.split(": ", limit = 2) }
18+
.map { (area, presents) ->
19+
val (areaX, areaY) = area.split("x", limit = 2).map(String::toLong)
20+
Tree(areaX * areaY, presents.split(" ").map(String::toLong))
21+
}
22+
23+
/** It seems giving each present a 3x3 area without overlaps produces the correct answer for the actual puzzle input */
24+
override fun partOne() = parseInput().count { (treeArea, presents) -> presents.sum() * MAX_PRESENT_AREA <= treeArea }
25+
26+
companion object {
27+
private const val MAX_PRESENT_AREA = 3L * 3L
28+
}
29+
}

0 commit comments

Comments
 (0)