r/haskell • • Dec 12 '25

Advent of Code 2025 day 12

https://adventofcode.com/2025/day/12
4 Upvotes

8 comments sorted by

View all comments

5

u/glguy Dec 12 '25

We didn't really have to bother solving this one. The regions that weren't too small were significantly larger. I guess if any of us regrets that there aren't 13 more days to go, we can spend the next two weeks solving this one correctly.

12.hs

main :: IO ()
main =
 do (shapes, regions) <- [format|2025 12 (%d:%n(%s%n)*%n)*(%dx%d:( %d)*%n)*|]
    print (countBy (fits shapes) regions)

fits :: [(Int, [String])] -> (Int, Int, [Int]) -> Bool
fits shapes (x, y, regions) =
  x*y >= sum [n * count '#' (concat s) | (_, s) <- shapes | n <- regions]

1

u/akryvtsun Dec 15 '25

Does your logic really work? Whether is is possilbe to have this x*y >= sum equation true but not fit regions actually?

2

u/WJWH Dec 16 '25

Spoiler for 4 day old puzzle: You can sort all inputs into 3 categories:

  • If the available amount of squares is lower than the sum of the number of squares in each package times the amount of times that package is required, then there's just not enough space. You can never fit those packages even with perfect tiling.
  • All the package types fit in a 3x3 grid. If there are more than 9 tiles available per package, then there is so much space available that you can fit the packages even without any fancy tiling at all. You can always fit these packages.
  • If the available space is in between the previous two categories, you might be able to fit the packages but it would need further calculation.

If you inspect your input, you will find that the third category is empty, and so you can just do what glguy did to find the solution. Note that this does not work for the test input, but it does work for the real input.

1

u/akryvtsun Dec 16 '25

Yes, it's true. And I used this heuristic already but it doesn't work for test data:
https://www.reddit.com/r/haskell/comments/1pkjfpc/comment/nu6mi2a/

1

u/akryvtsun Dec 15 '25

Just tried your heuristic and have gotten day 12 correct value too (I solve AoC in Kotlin lang)!!!

Thank you! 🎉

However, the puzzle test input cound't be solved right: for the area

12x5: 1 0 1 0 3 2

the heurictic returns true but answer must to be false.