r/adventofcode • u/daggerdragon • Dec 12 '25
SOLUTION MEGATHREAD -❄️- 2025 Day 12 Solutions -❄️-
A Message From Your Moderators
Welcome to the last day of Advent of Code 2025! We hope you had fun this year and learned at least one new thing ;)
Many thanks to Veloxx for kicking us off on December 1 with a much-needed dose of boots and cats!
/u/jeroenheijmans will be presenting the results of the Unofficial AoC 2025 Participant Survey sometime this weekend, so check them out when they get posted! (link coming soon)
- edit 1: link: [2025] Unofficial AoC 2025 Survey Results!
- edit 2: now with bonus content!
There are still a few days remaining to participate in our community fun event Red(dit) One! All details and the timeline are in the submissions megathread post. We've had some totally baller submissions in past years' community fun events, so let's keep the trend going!
Even if you're not interested in joining us for Red(dit) One, at least come back on December 17th to vote for the Red(dit) One submissions and then again on December 20 for the results plus the usual end-of-year Community Showcase wherein we show off all the nerdy toys, the best of the Visualizations, general Upping the Ante-worthy craziness, poor lost time travelers, and community participation that have accumulated over this past year!
edit 3:
-❅- Introducing Your 2025 Red(dit) One Winners (and Community Showcase) -❅-
Thank you all for playing Advent of Code this year and on behalf of /u/topaz2078, your /r/adventofcode mods, the beta-testers, and the rest of AoC Ops, we wish you a very Merry Christmas (or a very merry Friday!) and a Happy New Year!
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2025: Red(dit) One
- Submissions megathread is
unlocked!locked! 5 4 3 2 1DAY6 HOURSremaining until the submissions deadline on December 17 at 18:00 EST!3 2 1DAY6 HOURSremaining until the poll closes on December 20 at 18:00 EST!!!Come back later on Dec 17 after 18:00ish when the poll is posted so you can vote! I'll drop the link here eventually:[link coming soon]edit:VOTE HERE!- edit2: Voting is closed! Check out our end-of-year community showcase and the results of Red(dit) One (this year's community fun event) here!
(link coming soon) - edit3: -❅- Introducing Your 2025 Red(dit) One Winners (and Community Showcase) -❅-
Featured Subreddit: /r/adventofcode
"(There's No Place Like) Home For The Holidays"
— Dorothy, The Wizard of Oz (1939)
— Elphaba, Wicked: For Good (2025)
— Perry Como song (1954)
💡 Choose any day's Red(dit) One prompt and any puzzle released this year so far, then make it so!
- Make sure to mention which prompt and which day you chose!
💡 Cook, bake, make, decorate, etc. an IRL dish, craft, or artwork inspired by any day's puzzle!
💡 And as always: Advent of Playing With Your Toys
Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!
--- Day 12: Christmas Tree Farm ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
4
u/DeadlyRedCube Dec 12 '25
[LANGUAGE: C++]
Parts 1 & 2 on GitHub
lol
Started doing this and thought "let's just see how many can be ruled out by the obvious tests" and then ... lol
well played.
Test runs in 2.0ms (which is somehow slower than some other, way more functional days?)
Total runtime for all days: ~71ms on my Core i7 8700K. Not bad! Most of that is days 8 and 10.
Great work on the puzzles as usual! (and great modding, u/daggerdragon as usual - sorry no cubes this year!)
3
u/codevogel_dot_com Dec 12 '25
[Language: C#]
Unfortunately, today I got spoiled halfway through solving it. I'd written a parser, then had to go to work. Opened up Reddit on my way back home, and a meme showed up in my feed, pretty much ruining today's Eureka moment for me. Luckily it didn't spoil the trick fully, but I knew there was a trick, which led me to finding the trick with much more ease than I otherwise would have.
Kind of left a sour taste in my mouth. I hope next year we implement some stronger rules on adding spoiler tags to this sub. I'm not even subbed to it.
All in all a very fun year though. I like dropping down to 12 puzzles. Leaves me more time to do other stuff in December. It also proved much more accessible year for my students in our in-school leaderboard.
https://github.com/codevogel/AdventOfCode/blob/master/2025/day12/Solver.cs
3
u/chestck Dec 13 '25
[Language: Kotlin]
very disapointed in this last day. Why not reduce the possible solution space size and make it an actual packing problem?
ANyway here it is golfed in kotlin
3
u/flwyd Dec 14 '25 edited Dec 14 '25
[Language: sed] [Language: awk]
Since the input file is degenerate, why not a degen Unix pipeline? This uses
sedto turn each line (except the shapes) into a comparison operation, usesxargsto evaluateexpron each line, which outputs0or1if the pieces can or can't fit. Then runsedagain to insert a+at the start of the line and runxargs expragain, injecting a0to start the sum. Takes about 15 seconds (though my computer is busy running my Ruby script too), since it forks 1000exprinvocations.Solve today's puzzles
✅ The wrong way
✅ Using only the most basic of IDEs
manlookups.✅ Using only the core math-based features of your language (e.g. only your language’s basic types and lists of them); No templates, no frameworks, no fancy modules like itertools, no third-party imported code, etc.
✅ Without using if statements, ternary operators, etc.
✅ Without using any QoL features that make your life easier (No Copilot, no IDE code completion, no syntax highlighting, etc.)
❓ Using a programming language that is not Turing-complete
sedis apparently Turing-complete, but in a bit of a Turing-tarpit way. This doesn't use those features, though, and I don't thinkexpris Turing-complete: it has conditionals and logical operators but no loops and no way to read input.✅ Using at most five unchained basic statements long.
❌ Without using the [BACKSPACE] or [DEL] keys on your keyboard
^Wto delete a word several times.❌ Using only one hand to type
❓ Make your solution run on hardware that it has absolutely no business being on
✅ Reverse code golf (oblig XKCD)
awk -F'[x: ] ?' '{a+=($1*$2)>($3+$4+$5+$6+$7+$8)*7}END{print a}'✅ Why use few word when many word do trick?
✅ Use unnecessarily expensive functions and calls wherever possible
❌ Implement redundant error checking everywhere
1000then I know it's not working.❌ Javadocs >_>
nroffas a glue language this month until writing this comment.That's what she
sed!3
u/e_blake Dec 14 '25 edited Dec 14 '25
[LANGUAGE: m4]
I successfully avoided reading the megathread until after my gold star. And I totally got trolled by the example puzzle. I didn't even try to start coding it yesterday (I was still trying to finish day 10 part 2), but I did take time to google for packing algorithms, and was very depressed to see NP-Hard being mentioned in so many instances. Then today, I figured I at least ought to get parsing working (always interesting in m4 which lacks a readline primitive; but today's parsing was more fun than usual because I achieved O(n) parsing in POSIX, compared to many days which only get O(n log n) parsing, thanks to a well-placed ": " pair). Then I coded up a filter to try and determine how many rows were trivially pass or fail, to get a feel for how many hard rows remain - of course, all 3 rows of the example are hard, and as the rest of you have figured out by now, NONE of the 1000 lines in my input were hard, with a runtime of < 60ms on laptop battery. So with that, I have joined the 524 star club!
m4 -Dfile=day12.input day12.m4
I will follow up with my submission for the contest; today's solution was fun enough that I want to see if I can do it golfed to a single m4 define.
2
u/TallPeppermintMocha Dec 12 '25 edited Dec 12 '25
[Language: Python] I tried with having all sizes be their actual size, 7 or 8, and all of them led to the same number of valid grids. I tried solving the more challenging problem with overlaps for a grid filling algorithm and failed -- but that's for tomorrow.
Another fun year of puzzles, brings me great joy to solve these every year and to read through creative solutions here. Thanks Eric for keeping this going and to /u/daggerdragon for all your hard work around here!
2
u/vk6_ Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python]
I tried to code golf today's solution since it was so much simpler than expected:
It's 124 characters long.
2
u/Smylers Dec 12 '25
[LANGUAGE: Vim keystrokes] Load your input (and definitely not the sample input!) into Vim and type:
The number of lines in the file is today's part 1 answer.
Line 1 above joins each present onto a single line, removes everything that isn't a
#, and replaces each#with+1, so a present occupying 6 units becomes+1+1+1+1+1+1— an expression that evaluates to 6.The next line sticks those expressions in brackets and temporarily prepends
-\2to each, before usingg⟨Ctrl+A⟩to renumber them, so the first present is numbered\3, the next\4and so on. Then they're all joined into a single line.The middle line inserts a partial
:%scommand at the beginning of that line. With the6arepeating a bit in the middle, the line will end up looking something like the following, except with different numbers of+1s depending on your input:Then
dddeletes that line, and@1runs the text in the just-deleted line as Vim keystrokes — in other words, it executes that dynamically constructed:%s///command. That operates on all the remaining lines in the file, the regions. For example, the12x5: 1 0 1 0 3 2example region would be transformed into something like:Then
@lfrom some previous day is used to evaluate the expression after the colon on each line (the only reason the colon and space were inserted today was so I could re-use that). That calculates the area of each region and then subtracts from it the areas of the required numbers of each gift.The final line above deletes all the lines containing negative numbers — where the presents' area is greater than the region's. All the remaining lines have nice big numbers on them, so let's presume everything else fits. Merry Christmas!
2
u/Wild_Mark_359 Dec 15 '25
[LANGUAGE: c++] I implemented a backtracking algorithm with cache for the solution. It found the solution to the example in about 17 seconds, but failed with the real input. With little hope, I additionally implemented an area check, which did not help with the example. Well, it couldn't hurt to try it on the real data, and tada, I got the star.
https://github.com/volkerbecker/advent_of_code_2025
24
u/nickponline Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python]
200 lines.
SAT using the dihedral group of each shape.
https://github.com/nickponline/aoc-2025/blob/main/12/main.py
16
u/vash3r Dec 12 '25
[LANGUAGE: Python] paste
It's always worth investigating if the problem is actually as difficult as it seems before solving the hardest version.
13
u/4HbQ Dec 12 '25 edited Dec 13 '25
[LANGUAGE: Python]
I had to shorten my code a little bit to make it punchcard sized, but I think it's still pretty readable:
We're can use a helpful property of the puzzle input today: the regions are either too small to fit all packages, or they are very oversized. Each shape is at most 3 by 3, so if our area can fit n of those, we're good.
This solution might not appeal to the puzzle purists, but I'm on team "if it works, it works!"
A somewhat cleaner solution would be to distinguish between three different cases:
Actually I was expecting the input would contain a few non-trivial but still feasible lines, e.g. to be solved by hand. I did even bring some grid paper and scissors to my desk when I got my second cup of coffee!
And that's a wrap for AoC! Thanks /u/daggerdragon for keeping things nice and clean around here, and /u/topaz2078 for creating the puzzles. I've really enjoyed them, and didn't mind the shorter event duration at all.
Thanks to all who replied, especially /u/pred, /u/xelf, /u/AlexTelon and /u/JWinslow23 for their useful comments.
Since I don't have a code repository and my comment history contains a lot of other comments, here's a list of my main posts of this year: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. Similar lists for earlier years: 2024, 2023, and 2022.
I could copy all code into some kind of repository, but we would lose all context: explanations, useful replies, etc. Please let me know what you think!
2
u/Practical-Quote1371 Dec 13 '25
[LANGUAGE: TypeScript]
I was shocked when I saw that today's puzzle was a packing problem since I posted a packing puzzle of my own back in July (Secret Santa in July). Check it out if you want a challenge! u/ssnoyes has the current fastest solution at 45 minutes. My fastest solution takes about 2 hours longer than that.
Since I reused some of that code for today my solution is a bit over-engineered, but it gets the job done and I get reuse points: GitHub.
Coming here after solving it on my own I'm just now seeing all the comments about the short-cuts. I found one of them on my own and included it in my solution, but not the other one, so my solution still does a lot of packing work and takes several minutes to complete.
I have to say, I kind of enjoy these types of hidden optimizations.
9
u/Old-Dinner4434 Dec 12 '25
[LANGUAGE: TypeScript]
GitLab
I use Bun runtime engine, running on 2021 M1 Pro MacBook Pro. Part one completed in 5.08ms. There was no part 2.
Eric, you're a madlad. I love you man. What you managed to pull on us on the last day is incredible. I don't remember the last time I laughed so hard and was so happy at making something work in a long time. You've actually made me belly laugh. Thank you. Truly thank you, what a fantastic way celebrate 10 years of AoC, what a way to go. I can't stop saying thank you, because the joy your work brings, and the absolute troll today, it's phenomenal. Marry Christmas, and a Happy New Year! Stay safe, everyone.
7
u/Boojum Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python] 01:03:09 / 01:03:20
Well played for the last problem!
I actually did write a packer. So I can claim that I've solved this "properly" and my code verifies by existence that there's a solution. Of course, exhaustively proving that there's no solution by doing test packings takes way longer. Fortunately, the input is constructed so that just checking if the area of the rectangle is big enough to hold the sum of the area of the shapes is all you need to rule out the ones that don't work. And the real input here also seems like it might be designed to be relatively quick to find a valid packing for the cases where the rectangle is big enough.
This runs in about 3:22 on my machine on the full input. Interestingly, it takes about that long to run on the example, determining that there's no solution for the last line of the example. Of course, with the way the input is designed, commenting out the
add add()and just going on the heuristic alone is sufficient and nearly instantaneous.This is definitely my largest solver program this year!
As always, thanks to /u/topaz2078, /u/daggerdragon, and the community for making this a fun event. Special shoutout to /u/morgoth1145 for some fun discussions.
6
u/davidsharick Dec 12 '25
[LANGUAGE: Python]
Code
Pretty trolly problem today, fits for day 12 though; when I first read it I thought we were getting an insanely difficult problem because of the compressed difficulty curve
6
u/SquireOfFire Dec 12 '25
[LANGUAGE: Python]
I got that far, then started thinking about how to actually do the hard part. But there's actually quite a few that can fit with just this naive check, so let's try that as the answer...
No way. I was prepared for this to take all week.
6
u/Parzival_Perce Dec 12 '25
[LANGUAGE: Python]
Well that's AoC 2025 done! It was fun, though I don't feel great about this one.
So we were semi-ranting about how annoying this seems and vaguely about what ideas people have, when some dude in the server goes 'check for areas!'
And we're like lol that's so stupid it couldn't work. And then we were like see it fails on even the example input.
'But it works on the actual input tho' ...eh. I'm sure those who realised this themselves are happy with themselves. For me it's just eh.
6
u/Andreasnl Dec 12 '25
[LANGUAGE: Uiua]
6
u/biggy-smith Dec 12 '25
[LANGUAGE: C++]
A genuinely unsatisfactory problem to end the year on. It feels against the spirit of things somehow. ah well...
https://github.com/biggysmith/advent_of_code_2025/blob/main/src/day12/day12.cpp
5
u/835246 Dec 12 '25
[language: rust]
Part 2 is too hard today I don't think I can solve it so only my part 1 solution.
Part 1: https://github.com/efox4335/advent_of_code/blob/main/advent_of_code_2025/src/day_12_part_1.rs
4
u/abnew123 Dec 12 '25
[LANGUAGE: Java]
The generalized solution to this problem feels insane (might even be NP complete?) but the naive check of if each present has a reserved 3x3 was enough at least for my input.
Edit: From scanning the input again, I think either the naive upper bound (give 3x3 region to everything) or the naive lower bound (give each present exactly n cells where n is the number of cells it occupies) works.
Solution
Live Solve
4
u/Aspen138 Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python]
Use greedy strategy.
The Python code parses the six 3×3 shapes and all regions from the text input, generates every unique rotation and horizontal flip for each shape (stored as
#cell offsets plus height/width), prunes any region whose total required#cells exceed its area, then greedily tries to pack the remaining regions by expanding the requested pieces, sorting them largest-first, and scanning an h×w boolean board to place each piece using shuffled orientations (two deterministic seeds to avoid unlucky ordering); if all pieces place, the region counts as feasible, otherwise not, and summing feasible regions yields the printed result of Part1.paste
4
u/jonathan_paulson Dec 12 '25
[Language: Python]. My times: 00:07:57 / 00:08:01. Video of me solving.
Very troll-y problem! Looks super hard (I have no idea how to do it efficiently), but then all the actual input cases turn out to be very easy (either there is physically not enough space or there is so much free space it must be possible).
4
u/wimglenn Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python]
Incredibly evil puzzle. 😠 Was thinking about how the heck to solve it for a good 20 minutes before actually eyeballing the numbers and understanding what Eric was up to here. What a sneaky trick! 😂
4
u/Ok-Bus4754 Dec 12 '25 edited Dec 12 '25
[Language: Python]
i am interested in knowing if this is only me or if it works for every input !
i was going to try to do all the shapes rotation and try to fit everything using backtracking or something, but i began by checking for total available sizes as an early heuristic !
i tested the answer with the regions that at least have the available sizes, and it worked !
i am not happy about this solution
https://github.com/Fadi88/AoC/blob/master/2025/days/day12/solution.py
p1 : 1.3 ms
4
u/morgoth1145 Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python] code video Times: 00:23:24 / 00:23:28
So we have something Tetris-adjacent here! I was bracing for a hard packing problem to fit the shapes in but submitted an answer with a super dumb packing test instead (just counting the squares in the pieces and whether they even possibly could fit in the shapes) and it was the right answer! I'm guessing it's more likely with larger regions due to how tightly the presents can be packed in practice in bulk but I definitely don't have a hard math proof of this. (Certain inputs can be crafted even at larger scales which would break this test but I suspect the problem and inputs are crafted specifically to allow the dumb test to work.) I'll be interested in a more proper solution to be sure, but I'm glad I submitted the stupid answer. I was fully prepared for a 1 minute timeout here! (I was left gobsmacked when it worked which is very apparent in my video.)
I left my WIP code for a larger solver largely in-tact in this push just to show the thought process I was going down, I'll clean it up in a follow-up.
Edit: Cleaned up solution using only the count-based filtering methods. This does verify that there are no regions that are still ambiguous just in case someone comes up with a part 3 at some point (or in case I want to have this actually solve the test input).
4
u/Kehvarl Dec 12 '25
[LANGUAGE: Python3]
I spent an hour building transform tools, writing a DFS thing with memoization, and having it take forever on the test. Then stripped it all down to just checking if the region is even big enough for the squares taken up by the presents. That fails on the test, but the solution worked for my input.
I'm still trying to solve it "properly" though. Reading lots about the Packing Problem...
paste
4
u/cmaro2 Dec 12 '25
[LANGUAGE: Python]
Decided to try a one liner before even thinking about how to correctly solve it and it worked. Not sure if I was happy or sad about it.
4
u/TiCoinCoin Dec 12 '25 edited Dec 12 '25
[Language: Python]
Final day: day 12
I know I'm not the only one who parsed, flipped, rotated, implemented an algo, just to hit the runtime wall (I mean, 5 minutes on this small test case?). And then, I tried to narrow the number of candidates, by removing the obvious fails (area is smaller than the sum of the shapes sizes). I submitted the remaining number of regions "just in case" and tada!
It feels strange to know that this was the last day today. But it's also nice to know that I can go back to living a normal life (which is pretty busy in this season !)
Thanks a lot Eric! And see you all next year (hopefully)
4
u/tymscar Dec 12 '25
[LANGUAGE: Gleam]
Last day of the advent. Thank you, Eric, and the team for another fantastic event. They always bring me so much joy.
This year, I loved every single puzzle except this one. Not because it's bad, but because it involves making assumptions about the input, and I am just one of those weird people that doesn't love to do so. But even then, 11/12 puzzles were fantastic.
At first, I spent like 20 minutes thinking about every single way this could be done, but it just felt impossible. No way I could write anything that would run in any reasonable amount of time. I knew I had to do some pruning of the input, but then a friend spoiled that this is more of a troll problem, and literally using the heuristic of "do the areas of the pieces when fully interlocked, would they fit on the board" is enough to get the correct answer.
I coded that up then in a few minutes and unlocked the last 2 stars.
Looking forward to next year!
Solution
4
u/tcbrindle Dec 12 '25
[Language: C++23]
At least I can go back to trying to do Day 10 Part 2 now...
Github: https://github.com/tcbrindle/advent_of_code_2025/blob/main/dec12/main.cpp
4
u/ash30342 Dec 12 '25
[Language: Java]
Day 12
So... I implemented a complete backtracking solution, including all necessary matrix transformations. Took some time, but worked perfectly for the example input, then I tried on the real input and waited for the result for the first region. And waited... and waited...
I should have known.
Then I tried what many of you did: just calculated the number of shapes times their area and checked if the region had a size of at least that number. That turned out to be the answer.
One of the few (only?) times the real input was easier than the example input. Ah well! I left the original backtracking solution in the source file, took me enough time ;-)
Anyway, that's 522 stars for me. I just need to get back to day 10 part 2. Using an ILP solver is against my own rules, so that will take a while...
Thanks once again to Eric! I have really enjoyed myself once again and really do not mind having less days. Looking forward to next year!
4
u/decliqu3 Dec 14 '25
[LANGUAGE: Python]
I can't believe this worked 🙈
1
u/WilkoTom Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Rust]
Solution
If there were any more red herrings in this challenge, Eric could open his own fish market. Very, very straightforward for my input - assume all the presents occupy an entire 3x3 square and check if they all fit.
Happy holidays to u/topaz2078 , u/daggerdragon and all the others who make this such a fun experience - Looking forward to the next 12 already!
1
u/encse Dec 12 '25
[LANGUAGE: C#]
Ok, this...
https://aoc.csokavar.hu/2025/12
1
u/Jdup1n Dec 12 '25 edited Dec 12 '25
[Language: R]
Github link
I wasn't excepting this to work, but I'll take it!
To u/topaz2078 & u/daggerdragon, thank both of you for your dedication and the incredible work you've put again into this year. It is thanks to you that every year we take such pleasure in helping those [redacted] elves.
1
u/Sigiz Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Julia]
Turns out an assumption of like a 20% spare space given the very low possiblities of perfect fits worked for me (Worked for test input and my input, may not work for everyone)
EDIT: Full Code
1
u/AvailablePoint9782 Dec 14 '25
[LANGUAGE: PHP]
All 12 days.
Very proud to finish each day within 24 hours.
I think I lowered my threshold for when to look for clues here on Reddit and elsewhere. My goal is still to learn, not just mindlessly copy. I'm fine with that part of my strategy.
I overdid it a couple of days. Not good when I forget to eat etc.
https://github.com/LiseAndreasen/AdventOfCode/tree/master/2025
3
u/1234abcdcba4321 Dec 12 '25
[LANGUAGE: JavaScript] paste
Been a while since we've had a "check the input for special cases that deliberately doesn't apply to the example" problem. Still took a bit because I was searching for if there was an algorithm that can actually solve this problem for real.
3
u/vanveenfromardis Dec 12 '25
[LANGUAGE: C#]
GitHub
I feel like I just got trolled. My input didn't require any actual tiling, even though at least one of the shapes would not cleanly pack into the others (it was shaped like a U, and no other piece had the corresponding male "peninsula").
The uber naive satisfiability predicate of "Is the minimum total area for these shapes less than or equal to the area of the region" yielded the correct answer.
Thanks for another fun season!
3
u/python-b5 Dec 12 '25
[LANGUAGE: Lily]
This was a strange one to end things off with. The problem, as described, seems incredibly hard - I'm not sure at all how I'd go about solving it. I spent about half an hour at first hopelessly writing a naive bruteforce search solution that had no chance of ever finishing, just to try and make some kind of progress. It turns out the input is really, really convenient, though, and so just checking for the absolute upper bound on required space is enough (not for the test input, only the real input). This seems to be intentional, given the puzzle's hover text. When taking advantage of that, the puzzle becomes trivial; the shape definitions can actually be completely ignored, even. Almost all of my code is just for parsing the input.
https://github.com/python-b5/advent-of-code-2025/blob/main/day_12.lily
3
u/RussellDash332 Dec 12 '25
[LANGUAGE: Python]
Finally done! One line of GOLFED code per day. I will make an editorial about this soon, will come back to this comment once it's up on my webpage
3
u/mattbillenstein Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python]
https://github.com/mattbillenstein/aoc/blob/main/2025/12/p.py#L33
Had no idea for almost an hour of just thinking about this and given the test I thought this must be a real problem for sure with some trick I'm missing.
So I decided to just parse the input and start poking at what this looked like - the actual input areas are so large compared to the pieces, it's conceivable that you could completely fill up to a couple of the edges minus the unreachable hole in one of the pieces.
So, I evaluated that a lot of the pieces fit by just taking an entire 3x3 tile - this solution did not work, it was just a bit low, so I then tried the next best thing - compute the theoretical minimum area and compare that to the bin area - and amazing, we were all trolled more or less.
Anyway, still had fun this year, bit of a let down it was shortened and so many of the problems were so relatively easy compared to problems in previous years. I may go back to day 10 and write a simple solver instead of using Z3 I guess.
Edit: Reflecting on this a little - and it sorta feels like LLMs have killed a lot of the fun of actual programming the last couple years. And maybe they had something to do with sorta killing some of this event - the leaderboard, the spirit of fun competition; and the last couple years of LLMs and cheating - feels like we sorta lost something here, but maybe I'm just reading too much into it, idk.
3
u/azzal07 Dec 12 '25
[LANGUAGE: awk] I'm glad this one was easier than appeared, now I can return to frying my brain on day 10 golf (after some rest).
3
u/jwezorek Dec 12 '25
[LANGUAGE: C++23]
So after I parsed everything and was thinking about using eigen for rotation matrices and thinking about how I was going to memoize packing states, etc., getting ready for doing a brute force search for a packing with backtracking, I decided to do the basic feasibility test first to see how many, if any, of the packings were obviously infeasible -- I was hoping maybe the trick was they all were except for one or something -- by just testing whether the region area is greater than or equal to the area of all the required polyominoes for each packing. It turned out about half of my input passes this basic feasibility test. On a whim I entered the exact number in just to see it be rejected for being too high as a sanity check -- if it was too low something is wrong ... and it was accepted. I still am kind of shocked and don't really understand if this can actually be deduced from the input ...
I actually don't get the joke at the moment ... but am kind of happy because although I do like packing problems this just seemed like it was going to take all day tomorrow and I don't need that right now ...
[github link]
3
u/HappyPr0grammer Dec 12 '25
[LANGUAGE: Java]
github
First, new classes were defined for the shapes and areas. The helper functions in the classes allowed me to easily add or remove all possible versions of each shape (rotated/flipped) in the area. Here, Area also checked whether it was possible to add a shape at a specific location or not.
Then, a brute force function was written that tests all possibilities.
Before calling the brute force function, I wrote a check to see whether the solution was possible at all.
The answer to the test was successfully determined after 6 seconds of runtime. So I thought: hey, this won't work with the real data.
When I ran the solution with the real data, it worked because the brute force function was superfluous :D.
Many thanks to everyone involved in making AoC possible. I'm counting down the days until 1.12.26!
3
u/Jadarma Dec 12 '25
[LANGUAGE: Kotlin]
A difficult packing problem to end on a high note, is what I thought.
Part 1: Honestly I had no idea how to begin tackling this efficiently, what data types to use, how much "brute force" is required, so I just parsed the input while I thought. Figured that the more I eliminate known impossible areas, the less I would waste, so the easy heuristic is to check that if we were to "average out" the present shapes and let them fit into 3x3s ignoring overlaps, does the tree have enough area to contain them? And checking that, to my surprise, worked on the input (but not the example, probably because it is too small for the numbers to average out).
This feels like a dirty trick and not the kind of solution I would want to end the year on, but this is a busy weekend for me so it will have to do for now. I will pretend that this was a reading comprehension / work smart not hard for the time being. Perhaps, if there was a single region to find a fit for, not one thousand, I would've took the time to try an actual packing search.
Part 2: The good news is at least I have collected all stars this year! I wish there was a part two, so in the end there would be 25 stars, just so the total counter was a bit nicer, but am happy nonetheless. Thank you Eric for another successful AoC event! Happy holidays to everyone as well!
AocKt Y2025D12
3
u/julian192 Dec 12 '25 edited Dec 12 '25
[Language: Python]
Funny thing about Part 1:
I was just experimenting because my brain was still trying to come up with a solution that didn’t take O(n!) runtime. So I built a function that checks whether there is even enough space, so when the number of possible spaces is smaller than the required number of places for all
#it obviously won't fit, and another function that checks whether they can simply be placed side by side using 3x3 spacing. I also added aelsecase that prints “solve manually.”I ran it just for fun, and there was no “solve manually” statement, and the answer was correct.
After reading the megathread, I feel like this was the intended solution or just a troll problem.
Anyway, it was fun while it lasted. See you next year (hopefully)!
Code: [ Github ]
3
u/jackysee Dec 12 '25
[LANGUAGE: Javascript]
https://github.com/jackysee/aoc/blob/main/2025/day12.js
Like other people, I wrote an area check first to see how it goes. I typed in the passing count to the answer and surprised to see I got a star! Then I go back to add a magic ratio for it to pass the sample input.
Now I think back, not only solving the packing problem the "REAL" way is hard, generating such puzzle input is also hard. So it makes sense to approach it the simple way first.
Thank you Eric for another wonderful year! I think making it 12 puzzles is a good decision. I did have problem on balancing time for the past years puzzle where I want to enjoy the vibe of doing aoc with the community at the same day and having time with my family, especially near the end. Now I can relax and feel satisfied. Thank you very much!
Have a merry Christmas everyone!
3
u/krystalgamer Dec 12 '25
[Language: Python]
Came up with two heuristics to cut the search space.
If the total area the presents would take is bigger than the available space then skip it.
If all the pieces can neatly fit in each own 3x3 space under the tree then count it.
Looks like it was enough :) Thank god I didn't try to solve the example.
Code: https://gist.github.com/krystalgamer/d064d6f1da7660e3b5503f8470ea060c
3
u/gyorokpeter Dec 12 '25
[Language: q]
I'm not a fan of this kind of puzzle where the solution doesn't work on the example input because there is some undisclosed pattern that you need to find in the real input that doesn't appear in the example.
3
u/robertotomas Dec 13 '25 edited Dec 13 '25
[LANGUAGE: Rust]
Gave up for a day. Going back to basics, I used an informative heuristic and instead of being close, it was correct. https://github.com/robbiemu/advent_of_code_2025/tree/main/day-12/src
min_needed_space is based on the smallest bounding rectangle for a pair of each shape (including their rotations and mirror) that results in a decrease in the number of periods, or just 3x6
Benchmarks:
no_std library builds:
cargo build --release --lib --target-dir target/lib-part1→ 79,056 bytes1
u/AzzaScribe Dec 12 '25
[LANGUAGE: Python]
2
u/ChrisMan174 Dec 12 '25
[LANGUAGE: Python]
Reading this problem I realized how hard it would be if it was real, wrote in a big loud warning of a print statement if there were any non-trivial solutions... and thank god it never went off.
2
u/r_so9 Dec 12 '25
[LANGUAGE: F#] paste
Happy Advent! This one was brewing to be a complicated puzzle flipping fest, but I decided to try the basic thing of just adding up the size * amounts and that was the right answer! Nice trick u/topaz2078 :)
This is the full solution minus input parsing:
2
u/mendelmunkis Dec 12 '25
[LANGUAGE: C]
Sometimes it's about knowing which requirements are extranous
140 μs
2
u/iZyle Dec 12 '25
[Language: Python]
2
u/lunar_mycroft Dec 12 '25 edited Dec 13 '25
[LANGUAGE: Rust]
Full code. Like others in this thread, I noticed that several of the regions trivially couldn't fit all of the required presents based on the area of the region vs the total area of the required presents and decided to try the answer that check alone gave me first, and found out it worked (which I admit mildly annoyed me at first, and I still might try writing a backtracking solver for the general case, if nothing else but to get a feel for whether solving it in the allocated time is even plausible). On my machine parsing takes ~130µs and solving takes 1-2µs.
There are actually two ways you can check if a region could possibly fit it's required presents: the best case scenario (and what I initially did) is to check if it would be possible to pack the presents in assuming maximal efficiency (no empty spaces that can't have another present inserted). The worst case scenario (e.g. /u/maneatingape's solution) instead checks if the presents can fit assuming that their bounding boxes do not overlap. According to my own self-imposed rules, I'm allowed to check if the puzzle input is a valid puzzle during parse time and then assume it is when computing the answer, so long as I don't do any of the computation for the actual solution as part of parse time. So I checked if the best case and worst case answers were the same at parse time. This slows down parsing by ~5-10µs, but doesn't effect the time taken to solve the puzzle.
2
u/Ok-Bus4754 Dec 12 '25 edited Dec 12 '25
[Language: Rust]
Port of my earlier Python solution.
1- parse all the shapes into a vec, for the shape we simply care about the number of "#' , or the actual size the shape occupies
2- for each region, get the region shape (w*h) and the total size of the shapes required sum(number of each shape *size of each shape)
3- if the total size is less than or equal the available size this region is valid
https://github.com/Fadi88/AoC/blob/master/2025/days/day12/src/lib.rs
2
u/giacomo_cavalieri Dec 12 '25
[language: gleam]
Since today's solution was kind of a cheat I challenged myself to make it as fast as I possibly could and boy is it fast, takes only 37μs 🔥
https://github.com/giacomocavalieri/aoc_solutions/blob/main/src/aoc_solutions/year_2025/day_12.gleam
2
u/ak-coram Dec 12 '25
[LANGUAGE: Common Lisp]
https://github.com/ak-coram/advent/blob/main/2025/12.lisp
2
u/nitekat1124 Dec 12 '25
[LANGUAGE: Python]
GitHub
I accidentally get the correct answer... I'm sure it's a prank or joke thanks to Eric lol.
but I eventually did a solution that works for both test data and puzzle input.
Merry Christmas everyone and see you guys 2026!
2
u/ziadam Dec 12 '25
[LANGUAGE: Google Sheets]
Expects input in A:A
Repo
2
u/RudeGuy2000 Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Racket]
uhh... alright.
EDIT: might as well give a few more words... when i was reading the problem description, i was already thinking of a complicated solution that involved stepping on all the presents, rotating or flipping it at first, then finding suitable positions, then recursing to the next present. basically a dfs, with memoization as an optimization (because of course memoization must be in the ending solution!), and stopping when suitable positions for all presents are found (so i must use call/cc?).
but the complexity and unfeasability of this solution is plainly obvious, so i just decided to go to the subreddit looking for exploits.
dirty? maybe... confused about my thoughts of today's problem? surely...
2
u/PangolinNo7928 Dec 12 '25
[LANGUAGE: Javascript]
Seemed only fitting to do a (very long) 1-liner :-D
Big thanks to u/topaz2078 for another super fun year!
2
u/lboshuizen Dec 12 '25
[Language: F#]
github.com/lboshuizen/aoc25
And that's it... 12 days of fun.
Polyomino bin packing with backtracking. Theoretical search space is 10965, early pruning and short-circuit evaluation reduce it to 68M actual attempts.
Full code on github
2
u/Illustrious-Idea6245 Dec 12 '25
[LANGUAGE: Python]
This problem can be trivially solved using Nubbenkopf's classic "Baloney Sandwiches of Fluegelstadt" chonk-finding algorithm, which I've implemented here using a slow-furrier transform reified over a spiral 5D matrix to compute the Eiswein coefficient for each slice in approximately O(n * q), where n is the number of atoms in the left spiral arm of the Andromeda Galaxy, give or take a rough order of magnitude, and q is the expiration date of the yogurt in my fridge (the opened one from last week, not the new one). Easy-peasy.
Thank you so much to Eric and everyone else involved in putting AoC together this year (and every year)!! I'm ordering my t-shirt as we speak.
2
u/MyAoCAccnt Dec 12 '25
[LANGUAGE: C#]
https://github.com/jsharp9009/AdventOfCode2025/tree/main/Day%2012%20-%20Christmas%20Tree%20Farm
I fell for the trap of looking at Reddit before getting my solution again, but it just confirmed what I figured. You don't need to arrange the presents in the actual input, just calculate areas and see if they will fix It doesn't work for the test case, but it works for the actual input. Maybe I'll go back and make it work for the test case too, after optimizing day 9 and 10s code.
2
u/Daniikk1012 Dec 12 '25
[LANGUAGE: BQN]
If I knew I was being pranked, the code would probably be much cleaner. What you see below is the result of removing the backtracking solution and replacing it with area calculation (I didn't feel like cleaning up). While it was fun, I feel so dumb for not discovering the fact I was being pranked by myself and that I had to look for help in this subreddit.
2
u/hugh_tc Dec 12 '25
[LANGUAGE: Python]
What a troll problem 🤣 - thanks for another year of Advent of Code, Eric!
https://github.com/hughcoleman/advent-of-code/blob/main/2025/12.py
2
u/qaraq Dec 12 '25
[Language: Go]
More effort parsing than solving.
Github: https://github.com/sekullbe/advent-of-code/blob/main/2025/advent12/advent12.go
Now to go back to Day 10 part 2 to finish up.
2
u/siddfinch Dec 12 '25
[Language: Free Pascal]
Day 12 - Xmas Tree Farm
Well, what a ride. A strangely enjoyable one, considering I showed up with a language roughly as old as I am and parked it beside a swarm of slick, popular languages with libraries for everything except, presumably, emotional resilience.
But in the end, none of that mattered. We're all just stories trying to parse ourselves. Understand the problem before you try to solve it, and the tool becomes incidental, just another character in the plot.
It's been a pleasure tackling all this alongside everyone.
2
u/b0f7df77e27a11 Dec 12 '25
[Language: Python]
After figuring out the trick to today's problem (the memes helped), I decided to see what the shortest one liner I could write to solve the problem was. Possibly the most horrifying line of code I've ever written! Merry Christmas everyone!
2
u/JV_Fox Dec 12 '25
[LANGUAGE: C]
Saw the possibility to clear some easy outliers with pruning lines that would never fit or would always fit. This result in such a heavy prune that I became suspicious. I looked at packing algorithms which turned out to be NP complete. Which caused even more suspicion.
I then started playing around with compression ratios for the puzzle blocks to see what the outliers would do that did not get pruned. After some tweaking this resulted in all results falling either side of the pruning with a result that was quite stable in the range of parameters I was trying. Attempted the result with some high suspicion and it was correct so I left it as is.
I anticipated quite a tough day so I anticipated a solution using pattern caching and recursion which where all not necessary. Just like my code pruned the solutions I pruned the code to the bare essentials to clean it up and speed it up.
Solution: Puzzle 12
Project: Embedded AoC
2
u/LtHummus Dec 12 '25
[Language: Scala]
Oh Eric, you memer. Love it.
My goal of doing every day in a different language was a success. The languages picked (in order): C, Clojure, Kotlin, Lua, MATLAB, C++, F#, Java, Perl, Python, Swift, Scala
Clojure, Kotlin, Lua, F# were brand new to me and I really really liked F#
Anyway, Scala it is and it's pretty succinct if you make those giant assumptions that the input lets you make
paste
2
u/icub3d Dec 12 '25
[LANGUAGE: Rust]
What a fun day and a great end to the year! It was best summed up by: read problem, panic, start looking for simple cases, imagine grin on puzzler's face, LOL. I did try to do some optimizations for just the sample and it was still a very hard nut to crack.
Solution: https://gist.github.com/icub3d/8b2d1c78a378de462418385c4fff3003
Video: https://youtu.be/DHtNCDnwOLA
2
u/JWinslow23 Dec 13 '25
[LANGUAGE: Python]
Solution writeup
Code (GitHub)
I was fully expecting some sort of complicated or long-running solution to this one. But as many have pointed out here, you can get by with some very simple heuristic checks. Just to make sure, though, I went ahead and added the following line, which runs if these checks fail:
This year, I've been putting detailed solution writeups on a new dedicated section of my website. Thank you to everyone who's been reading my 2025 writeups, especially u/dannybres and u/4HbQ! It's been fun to both learn from and teach others throughout this event. Congratulations if you were able to get all 24 stars!
Over the next few days, I'll also be finishing up The Brahminy (my AoC 2025 Python one-liner); I'll be sure to post about it once that's done.
2
u/Radiadorineitor Dec 13 '25
[LANGUAGE: Dyalog APL]
2
u/e_blake Dec 14 '25 edited Dec 14 '25
[LANGUAGE: golfed bash]
If your input is in a file named I, this bash solution is only
7470 bytes long (65 if you are okay learning the answer from bash's error message about command not found if you omit the echo):2
u/decliqu3 Dec 15 '25
[LANGUAGE: Python]
https://github.com/andreis/aoc/blob/main/2025/12-1.py
No external dependencies. An "actual" solution using a pruned DFS with bitmask collision checks and symmetry breaking. Runs in <1.5s
2
u/3j0hn Dec 15 '25
[LANGUAGE: Python] Jupyter Notebook
I figured I should post my "actual" solution using pulp. I wrote the check of triviality, but stupidly didn't bother to run it before embarking on an epic quest to solve to SAT problem. The pure SAT computation takes averages 5 CPU minutes per line of the input (highly variable) for 75 hours total CPU time using PuLP with the default CBC solver.
To make the SAT constraints easy to write I encoded the present shapes and all their rotations as 9 bit integers so I had variables T[x,y,s] == 1 iff shape s is centered at position x,y with 30 possible shapes, and grids around 45x45 this is about 61,000 binary variables lol.
The only tricky constraint was checking for piece overlaps but writing it down was made feasible by using bitmasks on s, so T[i,j,s] * (s>>k)%k == 1 iff shape s is centered at i,j and its shape covers the k-th square - since the bit-wise calculation is only the coefficient, it doesn't require the LP solver to do any integer division.
This was fun to write even if ultimately no needed to solve the problem. I initially ran this in Z3 (nearly the same code) but using Integer variables constrained to be 0 or 1, and that was about 10x slower, but possibly it would be just as if fast re-formulated with boolean operators.
2
u/xoronth Dec 17 '25 edited Dec 20 '25
[LANGUAGE: Python]
paste
And that's a wrap! Was a pretty fun one, definitely couldn't do it like previous years since I was travelling and problems were releasing at 5-6am, but it was still enjoyable.
My solutions can be found here for those who are interested. Warning that they're, uh, kinda scuffed.
Happy holidays to you all! See you next year!
2
u/nuancedreality Dec 25 '25 edited Dec 25 '25
[LANGUAGE: Java]
My solution wouldn't work without a cooperative input, but I basically filtered out two scenarios:
Disqualify inputs that could not possibly fit the presents in the rectangle
Auto-succeed inputs that fit without needing to interlock
3
u/maneatingape Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Rust]
Solution
25µs total. We can ignore the shapes completely and just check if the sum of presents fits into the area without any overlapping:
1
u/Tusan_Homichi Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Haskell] paste
I didn't honestly think this would work, but it was worth a quick try!
1
u/DFreiberg Dec 12 '25 edited Dec 12 '25
[Language: Wolfram Mathematica]
Like almost everyone else, I got set up to do some tiling DFS, wrote a basic check to filter out combinations and permutations which had too little remaining blank space...and found that this solved the problem entirely.
Setup:
Part 1:
Might be thirteen days early, but nevertheless: Merry Christmas!
1
u/rnbw_dsh Dec 12 '25
[Language: Python]
Parsing is left as an exercise to the viewer / here.
Seems to work with area multiplier threshold 0.82-0.87 (inclusive)
1
u/Mikey_Loboto Dec 12 '25
[Language: TS] (Node)
GitHub
:D
1
u/seligman99 Dec 12 '25
[LANGUAGE: Python]
github
I added a safety valve because I was going silly trying to figure things out .. and it worked. Huh. Was not expecting that.
1
u/Aggravating_Pie_6341 Dec 12 '25
[LANGUAGE: Java]
I spent the first few minutes thinking of a closed-form solution before trying out the method of checking if there were even enough spaces in the grid to fit all the presents, which turned out to give me the correct answer.
The number of spaces remaining is either negative or in the hundreds, making checking easy to do on the puzzle input.
(Time: 1296 / 1299)
Code
1
u/cay_horstmann Dec 12 '25 edited Dec 12 '25
[Language: Java]
I added a check that the ones that don't obviously fit cannot possibly fit. Leaving the actual grids in place for trying to solve the real problem later...
https://github.com/cayhorstmann/adventofcode2025/blob/main/Day12.java
1
u/hiimjustin000 Dec 12 '25
[Language: JavaScript]
https://github.com/hiimjasmine00/advent-of-code/blob/master/2025/day12/part1.js
1
u/Lindi-CSO Dec 12 '25 edited Dec 12 '25
[LANGUAGE: C#]
In pure desperation I tried the simplest form of packing check I could think of and miraculously it worked on the real input.
Day 12 - Part 1
1
u/lluque8 Dec 12 '25 edited Dec 12 '25
[Language: Scala]
Welp, the problem at hand was pretty hard core and I soon noticed that implementing rotations and swaps for everything is gonna be costly (reminded me of the dreaded sea monster problem few years ago). Instead a simple heuristic does the job in no time. Whole of AoC now wrapped, which is nice :)
Thanks to Eric and the team for this year. Of course kudos to the whole community too!
github
1
u/bigboots50 Dec 12 '25
[LANGUAGE: JavaScript]
1
u/PendragonDaGreat Dec 12 '25
[Language: C# CSharp]
Code: https://github.com/Bpendragon/AdventOfCodeCSharp/blob/70793d/AdventOfCode/Solutions/Year2025/Day12-Solution.cs
I both loved and hated this troll. It felt really awkward getting an NP-Hard problem on the last day so seeing the solution was that straight forward was kinda funny. See the solution didn't work on the example kinda tempered that because I like to also have my solution be valid for the given example data. It is what it is and I have all 524 stars.
1
u/amadejjj Dec 12 '25
[LANGUAGE: go] https://github.com/amadejkastelic/advent-of-code-go/blob/main/internal/solutions/2025/day12/solution.go
Part 1: 18.5µs
1
u/ItchyTrack_ Dec 12 '25
[LANGUAGE: Python]
1
u/FransFaase Dec 12 '25
[Language: C]
If you want to read some code for calculating all variants of a piece using rotations and flipping have a look at https://github.com/FransFaase/AdventOfCode2025/blob/main/Day12.md but otherwise, just skip it, because it was not needed to solve today's puzzles.
1
u/smallpotatoes2019 Dec 12 '25
[LANGUAGE: Python, C#, JavaScript]
Second time trying AOC live. First time completing it live (last year involved trying to complete the last few days at the in-laws on an old iPad - it wasn't ideal).
Tried to improve my JS this year, and I feel much more confident with Syntax at least. A mix of some quite nice solutions (I think) and some messy hacks that I can try and improve now. Loads of fun!
Python C# JavaScript
1
u/darren Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Clojure]
Github
Epic troll Eric! I spent so much time setting up grid rotation and placement code sweating how I would even start to track this one until I tried the obvious heuristics to see if I could whittle the search space down. Literally laughed when it led to the answer. Well played! Thanks Eric and all his helpers. Happy Holidays everyone!
This is way more code than is actually needed, but fun:
1
u/surgi-o7 Dec 12 '25 edited Dec 12 '25
[Language: JavaScript]
Feels especially fishy, but we have another 12 days to go and figure out a proper algo. I bet there's gonna be some upping the ante inputs around soon!
1
u/cicadanator Dec 12 '25
[LANGUAGE: Javascript - Node JS]
I started today's puzzle assuming I would have to write a jigsaw puzzle solver which would be slow and take a ton of time to implement and run. However, I decided to start by optimizing the number of puzzles I would have to solve by eliminating those that were too small to fit all of the gifts. When I did this I found the number of remaining puzzles in this case was the right answer. This may not hold true for every input and it did not work for the example but it did work for my input.
https://github.com/BigBear0812/AdventOfCode/blob/master/2025/Day12.js
If you are interested in a solution for solving puzzles like this then take a look at the link below. This is a puzzle solver I wrote a while ago for solving puzzles just like this based on a calendar puzzle I got as a gift.
https://github.com/BigBear0812/WholeYearPuzzleSolver
1
u/Szeweq Dec 12 '25
[LANGUAGE: Rust]
I hoped this will take forever.
github.com/szeweq/aoc2025/blob/main/day12/src/main.rs
1
u/johnpeters42 Dec 12 '25
[LANGUAGE: Python]
link
I started by manually computing an upper bound based on how many boards didn't have enough squares at all, regardless of positioning (about half), and a lower bound based on manually inspecting bounding boxes and checking how many boards could fit enough of those even if 100% filled (zero, though it sounds like this part was different for others, so maybe I managed to screw something up).
I could have just tried the upper bound there, but nope, I figured there might be a standard library for this type of problem, found it and worked out how to use it. It solved the sample input (taking a minute or so on the third one), but quickly crashed and burned on the real input. Then I gave in and looked up some posts here, and, well, here we are.
1
u/michelkraemer Dec 12 '25 edited Dec 14 '25
[LANGUAGE: Rust]
GitHub
Like everybody else, I just counted the number of required parts and compared it with the available area.
EDIT: I created a visualization that you can apply to your own input. See here:
https://www.reddit.com/r/adventofcode/comments/1pkrfpp/2025_day_12_i_know_it_fits_just_a_few_million/
1
u/ricbit Dec 12 '25
[LANGUAGE: Python]
I looked at the problem and immediately thought "oh my, we're having to bring a SAT solver today". I guessed that just writing the SAT model itself was going to be hard, so I implemented a brute force just to check the example. Brute force took about 44s to check the examples. When I was about to code the SAT, I thought, "let's try a simple check based on size", turns out the simple check was enough for the input.
Brute force
Simple check
I may try to actually build the SAT model tomorrow.
Thanks to Eric and all the mods for the fun!
1
u/seven_seacat Dec 12 '25
[LANGUAGE: Elixir]
Laughed my butt off when I realized the simple trick, before I thought about how to write a packing algorithm. Never even ended up parsing the present data.
https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2025/day12.ex
1
u/yieldtoben Dec 12 '25
[LANGUAGE: PHP]
PHP 8.5.0 paste
Execution time: 0.0009 seconds
Peak memory: 0.5113 MiB
MacBook Pro (16-inch, 2023)
M2 Pro / 16GB unified memory
1
u/se06745 Dec 12 '25
[LANGUAGE: Go]
https://github.com/omotto/AdventOfCode2025/blob/main/src/day12/main.go
1
u/jkrejcha3 Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python 3]
Just checking just area for my input didn't work (or maybe it did and I missed something), ultimately what I did was color each cell of the polyomino in a checkerboard pattern, and filtered by area for each cell color with a heuristic for area. It works on the test data as well. Not the most compact solution, but it does work
paste
1
u/[deleted] Dec 12 '25
[Language: Haskell]
Day 12 - 1.04 s
Brute force-ish, but I did implement some speedups like using bitfields to represent the regions and the shapes.
1
u/runnerx4 Dec 12 '25
[LANGUAGE: Guile Scheme]
paste lol
I tried so hard to adapt the Rosetta Code pentomino tiling solution to this problem and then checked the time and checked this thread.
1
u/yfilipov Dec 12 '25
[LANGUAGE: C#]
Advent of Code - 2025 - Day 12 - Pastebin.com
1
u/acquitelol Dec 12 '25
[LANGUAGE: Elle]
Relatively easy day today. Runs in 41.3ms on my M1 mac. That means all of my cumulative solutions run in 478.1ms! yay
GitHub: https://github.com/acquitelol/aoc2025/blob/mistress/solutions/12/solution.le
1
u/taylorott Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Python]
Well, I feel like a fool, but I didn't think to just check for basic feasibility. That would be too easy! They would never do that, right? (while ignoring all the other puzzles where there was some shortcut based on the problem input).
As such, I ended up implementing a backtracking based solver. Essentially, I sweep through every 3x3 zone in the grid, and attempt to place a polyomino. I have an early termination heuristic that compares the minimum required area for the remaining polyominos with the available area (union of all the possible 3x3 I haven't checked yet).
It works, but almost certainly only by the grace of the problem input itself (it took a couple second to run on the difficult example in the problem statement). I had to increase the maximum recursion depth to get it to work (too tired to rewrite to be iterative, maybe later).
Solution
1
u/KindComrade Dec 12 '25
[LANGUAGE: C#]
Super dirty solution)
Code - github
1
u/mkinkela Dec 12 '25
[LANGUAGE: C++]
This is it, all 24 stars collected like they are Pokemon :)
Thank you Eric for making my December enjoyable. I can't wait for Dec 2026!!!!
ps. The good thing about having only 12 days is that my wife won't wake up every day because of my alarms early in the morning xD
Mega dirty solution
1
u/aimada Dec 12 '25
[LANGUAGE: OCaml]
Solution
Thanks again Eric, AoC is always a nice way to finish the year.
1
u/a9sk Dec 12 '25
[LANGUAGE: Golang]
https://github.com/a9sk/adventofcode/blob/main/year-2025/day-12/main.go
1
u/erikade Dec 12 '25
[LANGUAGE: Go]
First, I want to give kudos to u/topaz2078 for the fun and the edition!
On GitHub
Runs in under 119μs,
All days, all parts in 9ms on M1/16GB
Happy Coding!
1
u/careyi4 Dec 12 '25 edited Dec 12 '25
[LANGUAGE: Rust]
Well, that was disappointing! In one way I'm happy it wasn't the hard thing, but on the other hand, I'm so disappointed it was the easy thing!
https://github.com/careyi3/aoc/blob/master/y2025/solutions/d12.rs
1
u/hextree Dec 12 '25
[LANGUAGE: Python]
Code
Video
1
u/pred Dec 12 '25
[LANGUAGE: Python] GitHub/Codeberg. Once upon a time, I wrote a few solvers for the case where inputs are rectangles, which is easy enough to adapt to polyominos. But it's nowhere near being fast enough for the cases here; I wonder if it's possible to work without somehow explicitly pruning on area ≤ 7 stock.
1
u/Octonut42 Dec 12 '25
[LANGUAGE: C#]
Gah - I did it the hard way like a brainless idiot without seeing what others noticed about the puzzle input. https://github.com/taicchoumsft/AoC2025/blob/main/Day12/Day12.cs
Backtracking with a hard stop at 1000 iterations, testing every rotation and flip. Came here to see how others pruned their solutions only to see I completely missed the point of the question.
1
u/MagazineOk5435 Dec 12 '25
[LANGUAGE: C#]
Pretty simple: https://github.com/stevehjohn/AoC/blob/master/AoC.Solutions/Solutions/2025/12/Part1.cs
Good fun year again!
1
u/timvisee Dec 12 '25
[LANGUAGE: Rust]
Short and fast. Heavily golfed though.
- Part 1 in 27 μs (0.027 ms)
- All days in 18.41 ms (parallel in 13.78 ms)
1
u/MarcoDelmastro Dec 12 '25
[LANGUAGE: Python]
I implemented a backtracking solution that can find solutions rather fast if a solution exists, but takes a lot of time to explore the full phase space in case it does not exist. My quick and dirty solution was to cut seaches that takes too long, and it worked! I'll work on possible optimisation and pruning options another time...
https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day12.ipynb
1
u/bakibol Dec 12 '25
[LANGUAGE: Python]
Topaz's paste
What a troll of a problem. See you next year!
1
u/wheresmylart Dec 12 '25
[LANGUAGE: Python]
Yeah, some of us wrote a packer to try and solve the test input before looking at the real one! I will spare you the details, but it's slow and it works. Took far too long with the real input so added some sanity checks on grid size.
Hmmmmmmmmmmmmmmm!
Paste
1
u/andrewsredditstuff Dec 12 '25
[LANGUAGE: C#]
I feel dirty - I only plugged the answer into the box to confirm that it was a valid upper bound before doing the actual work, expecting it to be rejected as too high.
I won't be able to look myself in the mirror until I do a proper generic solution (although not sure how to confirm that it actually is). (And let's face it, I've not gone back to any like this in the past, so unlikely to do so for this one).
github
(A bit overengineered for what the solution actually is, but I was of course expecting to have to do much more with it).
1
u/BroDadi Dec 12 '25 edited Dec 12 '25
[LANGUAGE: C#]
lol
1
u/No_Mobile_8915 Dec 12 '25
[LANGUAGE: Python]
A very slow (~22s without the cache, ~20s with, so the cache isn't getting hit much) solution that works on both the example and the real data:
paste
vs, all that was actually needed to solve on the real data (runtime: 0.0014s, but fails on the example data)
paste
Nice one Eric!
1
u/TheScown Dec 12 '25
[LANGUAGE: Scala]
Code
Uses DFS to find a workable placement at about 30s per line. I'm glad I came here before wasting my day trying to optimise it. The DFS is now commented out.
1
u/ednl Dec 12 '25 edited Dec 12 '25
[LANGUAGE: C]
https://github.com/ednl/adventofcode/blob/main/2025/12.c
EDIT: in my previous version I determined the number of parts (
#) of each shape, saved that as a vector (=array of length 6), and did an inner product with each tree vector of shape counts, to get the total area of the presents under the tree. So that's only the total number of#, no tiling. Count it as "it fits" when that is less than the WxH area of the tree. Already a huge assumption that doesn't require tiling at all. But /u/timrprobocom posted that simply assuming an average area of 8 per shape is enough! For my input that worked with 7 or 8. So now I don't even look at the shapes anymore :cry:Assuming the input file is in char array
input, this is my WHOLE program with comments removed:Runtime on an Apple M4: 2.0 µs, Apple M1: 3.4 µs, Raspberry Pi 5: 13.9 µs (internal timer, does not include reading from disk, does include all parsing).
The RPi performs relatively badly on this puzzle, not sure why. Because I calculate while parsing, I don't imagine there's much vectoring going on anyway (which the RPi possibly can't do).
1
u/p88h Dec 12 '25
[Language: Odin]
So this was fun. Not sure why I haven't tried the 'obvious' answer immediately, but instead I chose to build a visual aid. With that, I solved the first 5 or so levels (well, except the ones that couldn't possibly fit the amount of gifts) and it finally dawned on me that the may all be solvable.
I'll try making the game more playable over the weekend, but it's on GH if anyone wants to try:
Solution : [ GitHub ]
Game : [ GitHub ] [ YouTube ]
1
u/Avuvos2 Dec 12 '25
[LANGUAGE: Python]
Bitmasks backtracking, runs in ~40s
https://github.com/Avuvos/advent-of-code-2025/blob/main/day12/main.py
1
u/Adz_23 Dec 12 '25
[Language: Java]
https://github.com/Adz-ai/AdventOfCode2025/commit/c75530a9abef4bb444a13cd85e90f3f605d1b54a
Execution Time: 13 ms
1
u/EmmiPigen Dec 12 '25
[LANGUAGE: Typescript]
Like other i solved i using the area the present takes up comparing it to the grid space. I dont hate this idea, it was a breather compared to some of the others.
https://github.com/EmmiPigen/AdventOfCode/tree/main/2025/dec12
1
u/hrunt Dec 12 '25
[LANGUAGE: Python]
code
I tried writing a packer first, but I couldn't find a way to process the "doesn't fit" case fast enough. That didn't seem very "last day" to me, so I tried just seeing if the volume of the packages fit underneath the tree and it worked.
Maybe I'll try actually getting my packer working for the degenerate case later. Maybe not.
1
u/birdnardo Dec 12 '25
[LANGUAGE: Mathematica]
gg everyone, see you all next year (hopefully🎅)!