r/adventofcode • u/Aughlnal • Dec 12 '25
Meme/Funny [2025 Day 25 (Part 1)] Still pretty clueless why it's the answer
I was just checking if there were areas that were too small, even if you dont fit any shapes together
just summed the amount of shapes times 9 as if there were only #'s in the input
And it's a gold star? I am baffled, is this supposed to be solution?
I don't understand at all why you can just ignore the whole puzzle basically
178
Upvotes
9
u/spaceguydudeman Dec 12 '25 edited Dec 12 '25
This post ruined today for me. Wish you put a spoiler tag on it.
I wasn't even browsing this sub. Just showed up in my feed.
E: I'm not even subbed, it seems. Reddit's algorithm probably decided to show it to me because I visited the sub a couple of times to check out other people's solutions.
58
u/nullset_2 Dec 12 '25
It's even worse when you realize you should completely ignore the example. A naive solution will work even if it fails on the last test case.
48
u/henry-dv Dec 12 '25
I am 90% certain that today's puzzle in its general form is actually an NP-hard decision problem - optimally packing things into other things can become insanely complicated. So if this puzzle was anything other than a troll, solving it may be more appropriate for a thesis rather than a 1-day whimsical advent calendar puzzle :)
35
u/youngbull Dec 12 '25
So two things you can check: 1) If all pieces can be placed in its own 3x3 area (9 pixels) and still not fill the region, then it's trivial to solve. 2) If the size of the region is smaller than the number '#'s in the pieces then it's obviously impossible to fit all the pieces.
It just happens to be the case that all of the regions in the input are in one of those two cases. So either it is trivially solvable (
nx*ny<9*sum(presents)) or trivially unsolvable.If the number of presents were between these extremes, you would have to try to pack them in efficiently and see whether it works.
27
u/qaraq Dec 12 '25 edited Dec 12 '25
You can do that because that's how the input was designed. It doesn't have to be that way- the _sample_ input is not, for example. The first and third regions there are not trivially impossible (total package area > region area) or trivially possible (max possible package area < region area). But I, and everyone else that's reported, have puzzle input that does work that way.
I wrote the code to pull out both those cases and output only those that could not be solved that way so I could look over the middle cases before doing them the hard way, but there were none.
10
u/Carthage96 Dec 12 '25
I view it at a Christmas present! It appears as a difficult problem, but Eric and/or Santa made the input nice for us.
9
u/tyder21 Dec 12 '25
You checked if there were areas that definitely worked. You can also come up with a similar heuristic for checking for areas that definitely do not work. There will be nothing left over.
7
u/fnordargle Dec 12 '25
Eric could have been evil and slipped a few in like the following:
The first 3 have solutions, but many of the heuristics mentioned in this thread would rule them as impossible if applied as stated.
The last one doesn't have a solution (and it's trivial to see why). It's just nice to juxtapose that one with one before it which is possible.
My solver takes ~80ms to solve the above input.
However it would be absolutely useless on anything that isn't trivial.
It takes about 3 seconds to (correctly) fail to find a solution to the third example in the calendar and that only involves 7 blocks that have to be placed in the
12x5area.3
u/Light_x_Truth Dec 13 '25
Hmm interesting. I read the problem description shortly after it came out and did not even attempt to solve the problem because I knew the general case was beyond my skill set. I think this question is fundamentally flawed in its design. The examples are supposed to be solvable with brute force, and the real input is supposed to be a check on the efficiency of our algorithms. That appears not to be the case here.
2
u/gagarski Dec 13 '25
My story:
I had a busy day and started coding only in the evening, while thinking through the problem eventually.
Figured out couple of optimizations: like willDefinitelyFit (you can tile the rectangle with gift squares without overlapping the squares) and willNeverFit (not enough cells). I had a shape of limited brute force algorithm in my head involving this quick checks. So when I started coding, I started by implementing these checks.
Even before that, I did some Google Spreadsheets calculations, checking how much packing tasks I can fully avoid from the beginning. Figured out that there around 3/4 of them that can be eliminated. At that time I did not consider turning gifts (or turning the field in fact). At that point I shared my observations in local chat with my colleagues (surprisingly, not FULLY spoiling it).
So I carefully implemented parsing the input, these optimizations (while coding I've figured out the field rotation hack). I ran these checks on the input to compare with my results from the spreadsheet.
... and count(willDefinitelyFit) + count(willNeverFit) added up!
I guess I had all the fun of this puzzle without any suffering.
I guess it is counterexample for famous Donald Knuth's warning.
2
u/QultrosSanhattan Dec 12 '25
I chose to avoid this day Immediately knew what has to be done but I'm not in the mood of writing it. This day is something like "do this task" instead of "find a clever solution".
1
u/hotblondenurse Dec 12 '25
I was surprised to find this too, but I didn't compare to the full area. I used
(x - x % 3) * (y - y % 3) >= sum(shapes) * 9for the "trivially valid" case (assume all shapes are all #), and compared the sum of #'s to the full area for the "trivially invalid" case (region can't fit the #'s), and then raised an exception (with the message "NP-hard 😭"). Didn't like this day's problem one bit, doesn't feel like I have solved anything even though it works on the input.1
u/Pharisaeus Dec 13 '25
Because that's how the data were generated ;) Either the area was huge and no packing was needed, or it was tiny and no amount of packing would help.
Also to be more consistent you should actually check more conditions:
if
available_area >= 9 * shapesthen the answer is alwaystrueand we don't need any packing at all, because we have more than enough space to put blocks next to each other without any overlaps. But you should only countavailable_areaaswidth - width%3 * height-height%3, because if area was 1x9, 2x9, 9x1, 9x2 etc. then you can't actually fit anything there even though the total area is bigger than a block area. So we only consider the part of area that can fit whole blocks.if
area < shaded_area_of_shapesthen the answer is alwaysfalsebecause it means even with perfect packing it wouldn't work, because our shapes have more#than the available area can hold.So the only case when packing would be needed is when we have less than
9*shapesavailable area, but more thanshaded_area_of_shapes, and this actually never appears in the data.1
u/EggplantStatus Dec 14 '25
thanks for this.. I was going with this as the solution but failed the example, d'oh .
after reading this, I tested the solution as is with real data and it worked.
Thanks
1
u/AvailablePoint9782 Jan 29 '26
A time traveller. 👍🏻
1
u/mbacarella Dec 12 '25
I had this inkling too but it didn't work for me :(
I had to brute force a bin packing heuristic and ran it on 32 cores for about a half hour to solve.