adventofcode

2025-12-09T05:46:59.350859Z

Day 9 - Solutions

Apple 2025-12-11T17:56:16.564399Z

So this is the map I got.

snyssfx 2025-12-11T21:48:33.138659Z

omg that was hard, now to reading for other solutions

narimiran 2025-12-09T12:08:11.092739Z

🥲

genmeblog 2025-12-09T12:09:02.665069Z

No solutions today? I can share the image (working on part 2)

genmeblog 2025-12-09T12:57:59.495389Z

Made it by cheating a little bit... (edit: added a native algorithm without reaching for java2d features) https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2025/day09.clj

narimiran 2025-12-09T13:41:14.217349Z

OMG, I just did it! It's ugly as hell and very inefficient, but - it worked on the first try!

2025-12-09T15:12:53.566769Z

Yeah - I realized last night I didn't have a clear solution for part2 and opted for sleep. I have some ideas, but I'm unlikely to be able to get to it today.

rjray 2025-12-09T17:56:07.415249Z

I've been trying to adapt the algorithm from https://www.geeksforgeeks.org/dsa/how-to-check-if-a-given-point-lies-inside-a-polygon/, but it gave me the wrong answer. My answer was too high, which tells me the algorithm selected a box that shouldn't have qualified, as opposed to missing the correct answer and returning a smaller box. I suspect this is related to every edge having a slope of either 0 or Inf.

Boldizsár Rácz 2025-12-09T19:30:38.867669Z

Not perfect and slow (~3 mins on my machine) but gave me the correct answer. I'm basically checking the reactangle for each combination of input coords if the edge of the red/green area is crossing it.

genmeblog 2025-12-09T19:44:21.446149Z

My idea was based on two facts: (1) all vertices are ordered and create a closed path and (2) there is no rectangle outside. So the only rectangles which should be taken into consideration are those which are not intersecting with the path. The truth is that all intersect and the trick was to shrink them a little bit to detach them from the path. All coordinates are integers so it was enough to shrink by 0.1.

narimiran 2025-12-09T20:10:05.653709Z

With some pmap , I'm finally under 1 second for Part 2. (Without it, I'm around 2.5 seconds)

narimiran 2025-12-09T20:35:06.828199Z

And now I realized that I can throw out 80% of the things I've written — it is waaay easier to check if a rectangle is inside of a polygon. I guess the input was very nice to us.

narimiran 2025-12-09T22:06:59.548939Z

The notebook is finally here: https://narimiran.github.io/aoc2025/src/day09/

jurjanpaul 2025-12-09T23:11:45.196729Z

Finished after the company’s early christmas dinner tonight with the first idea that came to mind (skip boxes that are cut by any segment). Straightforward to code; fast enough, but not very. There does seem a lot of potential for small and large optimisations still. So, I should study the solutions already posted above. https://jurjanpaul.github.io/ape-cljs-playground/?code=KHJlcXVpcmUgJ1tjbG9qdXJlLnNldCA6YXMgY3NldF0pCgooZGVmIGlucHV0CiAgOzsgdG8gYmUgcmVwbGFjZWQgd2l0aCByZWFsIGlucHV0CiAgIjcsMQoxMSwxCjExLDcKOSw3CjksNQoyLDUKMiwzCjcsMyIpCgooZGVmbiBwYXJzZQogIFtpbnB1dF0KICAoLT4%2BIChzdHJpbmcvc3BsaXQtbGluZXMgaW5wdXQpCiAgICAgICAobWFwICMoLT4%2BIChzdHJpbmcvc3BsaXQgJSAjIiwiKQogICAgICAgICAgICAgICAgICAobWFwIHBhcnNlLWxvbmcpKSkpKQoKKGRlZiBwYXJzZWQKICAocGFyc2UgaW5wdXQpKQoKKGRlZiBzZWdtZW50cwogIChtYXAgbGlzdAogICAgICAgcGFyc2VkCiAgICAgICAobmV4dCAoY3ljbGUgcGFyc2VkKSkpKQoKKHByaW50bG4gc2VnbWVudHMpCgooZGVmbiB2KiBbdiBuXQogIChtYXAgKHBhcnRpYWwgKiBuKSB2KSkKCihkZWZuIHYtIFsmIHZzXQogIChhcHBseSBtYXAgLSB2cykpCgooZGVmIGFsbC1wYWlycwogIChmb3IgW1twICYgcmVtYWluaW5nXSAKICAgICAgICAodGFrZS13aGlsZSBzb21lPyAoaXRlcmF0ZSBuZXh0IHBhcnNlZCkpCiAgICAgICAgcSAobmV4dCByZW1haW5pbmcpCiAgICAgICAgOndoZW4gcV0KICAgIFtwIHFdKSkKCihkZWZuIHBhcnQxIFtdCiAgKC0%2BPiBhbGwtcGFpcnMKICAgICAgIChtYXAgKGZuIFtbcCBxXV0KICAgICAgICAgICAgICBbKGFwcGx5ICogKG1hcCAoY29tcCBpbmMgTWF0aC9hYnMpICh2LSBwIHEpKSkgcCBxXSkpCiAgICAgICAoc29ydC1ieSBmaXJzdCA%2BKQogICAgICAgZmlyc3QpKQogCihwcmludGxuICJwYXJ0MToiIChwYXJ0MSkpCgooZGVmbiBvdmVybGFwcz8KICBbW2ExIGIxXSBbYTIgYjJdXQogIChhbmQgKDwgYTEgYjIpCiAgICAgICAoPiBiMSBhMikpKQoKKGRlZm4gc2VnbWVudC1jdXRzLWJveD8KICBbW1tweCBweV0gW3F4IHF5XSA6YXMgYm94XSAKICAgW1theCBheV0gW2J4IGJ5XSA6YXMgc2VnbWVudF1dCiAgKG9yCiAgIChhbmQgKD0gYXggYngpCiAgICAgICAgKDwgKG1pbiBweCBxeCkgYXggKG1heCBweCBxeCkpCiAgICAgICAgKG92ZXJsYXBzPyBbKG1pbiBweSBxeSkgKG1heCBweSBxeSldIAogICAgICAgICAgICAgICAgICAgWyhtaW4gYXkgYnkpIChtYXggYXkgYnkpXSkpCiAgIChhbmQgKD0gYXkgYnkpCiAgICAgICAgKDwgKG1pbiBweSBxeSkgYXkgKG1heCBweSBxeSkpCiAgICAgICAgKG92ZXJsYXBzPyBbKG1pbiBweCBxeCkgKG1heCBweCBxeCldIAogICAgICAgICAgICAgICAgICAgWyhtaW4gYXggYngpIChtYXggYXggYngpXSkpKSkKCihkZWZuIHZhbGlkLXBhaXI%2FCiAgW1twIHFdXQogIChub3QgKHNvbWUgKHBhcnRpYWwgc2VnbWVudC1jdXRzLWJveD8gW3AgcV0pCiAgICAgICAgICAgICBzZWdtZW50cykpKQoKKGRlZm4gcGFydDIgW10KICAoLT4%2BIGFsbC1wYWlycwogICAgICAgKGZpbHRlciB2YWxpZC1wYWlyPykKICAgICAgIChtYXAgKGZuIFtbcCBxXV0KICAgICAgICAgICAgICBbKGFwcGx5ICogKG1hcCAoY29tcCBpbmMgTWF0aC9hYnMpICh2LSBwIHEpKSkgcCBxXSkpCiAgICAgICAoc29ydC1ieSBmaXJzdCA%2BKQogICAgICAgZmlyc3QpKQoKKHByaW50bG4gInBhcnQyOiIgKHBhcnQyKSkK&checksum=MTcxMTU3MDIzNQ%3D%3D

jurjanpaul 2025-12-09T23:23:47.348119Z

I did see the above visualisation by @tsulej before starting on part 2; that indeed helped a lot to not worry about some potential edge cases that the puzzle text seemed to allow (e.g. segments crossing each other, a potential largest box actually being on the outside of the polygon, etc.)

benoit 2025-12-11T00:17:54.496699Z

Compute a set of boxes to cover all the tiles and filter out rectangles that are not made out of those boxes 🙂 https://github.com/benfle/advent-of-code/blob/main/src/advent_of_code/2025/09.clj Now that I am done with my overly complicated solution I thought of a better one: compute the set of boxes that cover the ground (not tiles) and filter out the rectangles as soon as they intersect with at least one of the ground boxes.

2025-12-09T14:44:00.806639Z

Day 8 Part 1 - Question in thread.

2025-12-09T14:45:36.502019Z

I get that the shortest distance is between (162, 817, 812) -> (425, 690, 689) But then it connects (431, 875, 988), is it connecting this to (162, 817, 812) ? Then it connects (906, 360, 560) and (805,96,715) but doesn't say to where ? I can't make heads nor tails of what this is trying to explain at all.

2025-12-09T14:46:45.843489Z

Or are (906, 360, 560) and (805,96,715) a seperate circuit altogether

2025-12-09T14:47:17.148249Z

and I'm really just trying to go through my calculated distances and make 10 connections using unique junction boxes, even if this means they aren't all connected to each other ?

AC 2025-12-09T18:13:04.136229Z

Yes. Here's how I thought of it -- You have a starting pool of 20 circuits of length 1. After you add the first pair, you have a pool containing 1 circuit of length 2 (162, 817, 812) -> (425, 690, 689) and 18 circuits of length 1. The next pair gets added to the existing circuit of length 2. Now your pool is 1 circuit of length 3 (431, 875, 988) -> (162, 817, 812) -> (425, 690, 689) and 17 circuits of length 1. The third pair (906, 360, 560) -> (805,96,715) creates a new circuit of 2 and your pool is 1 circuit of 3, 1 circuit of 2, and 15 circuits of length 1.

👍 1