Yordi - A Lifelong Journey of Growth

Advent of Code 2025 - Day 12

We've made it! The North Pole has been decorated and Advent of Code 2025 is finished. But not before telling you something about what feels like the most dirty solution for a puzzle ever.

Check out my full solution for day 12 at GitHub.

Part one

Today, we need to place presents under the tree, as you do when it's Christmas. Each present is represented by a 3x3 grid, like so (this is one of the examples, there are five more such presents with different shapes):

###
##.
##.

Below the presents, we have grids (the space under a tree) to put these presents in, and a list of numbers telling us how many presents of a certain type we need to put in the grid:

4x4: 0 0 0 0 2 0

In the above example, we have a 4x4 grid and need to put two presents with the fifth shape in it (rotating shapes is allowed). For part one, we need to count the number of grids for which placing the required presents is possible.

I've tried to use the polyomino package to help me do this, and have come a long way. It works for grids where all presents fit under the tree, but times out (or never finishes) for grids that don't fit all the presents.

With all hope gone, I checked how Juhis solved today's puzzle, and was blown away. While you can probably write your Tetris-like solver, it's enough to check if the total number of space the presents would occupy is less than the total space in the grid. If so, we can consider the grid big enough to fit all presents, regardless of their shapes:

probably_fit += 1 if presents_for_region_length < grid.count else 0

More surprisingly, this method returns an incorrect number for the example input but returns a correct number for the actual input.

A bit of an anti-climax maybe, but we did it! We solved all puzzles for this year of Advent of Code!

Part two

After the first part, the next one is not an actual puzzle, but lets you get the final star for free if you've collected all stars from previous days.

I hope you will enjoy this year's Christmas and wish you all the best for the year to come!