Advent of Code 2025 Day 12: Tree Farm
It pays to analyze the data!
When I first read the puzzle today, it seemed computationally impossible given the size of our input. I knew a naive brute force approach would be too slow, but I thought possibly some clever pruning of the search tree might work. However, I also noticed some people on one of my leaderboards finished very early, and I thought this was the hardest puzzle of the year, so that surprised me. I think my subconscious began looking for a shortcut!
I wanted to get a feel for the real input, so I ignored the sample input, and noticed that the grids for the first few regions of my input were big enough to accept all the presents without overlapping! Could it be this simple? So, I submitted my answer of 1000 for all the regions, but it was too high :(
Ok, well, for the ones that failed the trivial, non-overlapping placement, just how bad is it? For example, if we could magically fit them perfectly, is there even enough room for just the individual slots of the puzzle? No, there is not enough room - they're all impossible!
So, the answer is just to sum the number of regions that allow a trivial, non-overlapping placement :)
Thanks Eric Wastl for another year of Advent of Code. I'm glad you chose to reduce from 25 days to 12 days instead of just quitting entirely!
Now, I'll go through the puzzles and code up solutions in Rust, but I'll do it at a much slower pace than one per day.
"""Advent of Code 2025: Day 12 - Tree Farm"""
from advent import parse, ints
regions = [ints(r) for r in parse(12, sep='\n\n')[-1].split('\n')]
def fits(w, h, *quantities):
return 1 if sum(quantities) <= (w // 3) * (h // 3) else 0
assert sum(fits(*region) for region in regions) == 528
