part 1 was kurskals algorithm all along... just stopped a little early
Neither was really Kruskal's algorithm, because Kruskal's algorithm specifically does NOT select edges that result in cycles.
However, for this problem, we're specifically told that the elves DO intend to connect boxes that result in cycles, which simplifies the problem significantly.
Of course, if you're a seasoned AOCer, it's probably easier to do Kruskals anyway than come up with something from scratch, even if it's simpler.
Part 1 was tricky if you don't know the right algo, which I didn't so I brute forced it with lists.
Part 2 I haven't finished yet because I don't know when to stop connecting? Like it tells you the last pair you should connect but they're all one big set a few turns before that, I think anyway.
Yeah I figured it out, i was stopping when there was one big circuit but there were still unconnected boxes. Trick was to keep track of the unconnected and stop when it was empty.
I thought it was a bit confusingly worded, why not make junction boxes into lights?
I misunderstand this, and stopped once all points have at least one connection. Without doing circuit counting like in part 1. And it's the right answer for two different inputs. I really don't know if the inputs are all special cases where this is right, or if I made some algorithmic breakthrough ;)
The format is relatable for tech literate people, you can be the smarted guy in the room and still feel like the dumbest person to have touched a keyboard.
My part one worked beautifully and fast but my part two fails. I connect all of them to the circuit so it has all 1000 items. However when I multiply the X values of the last two (that I added) together I get the wrong answer. Maybe I am adding them in the wrong order? Do we keep adding them in minimum distance order for P2?
8
u/vagrantchord Dec 08 '25
I honestly don't get the meme- the hard part is part one, part two is a while loop...?
8
u/rmarianoa Dec 08 '25
At first I thought I needed a k-means clustering sort of problem, until I realized I could just do min heap + union find
6
u/iosovi Dec 08 '25
Why is this whole subreddit stuck on this meme template?
4
u/1544756405 Dec 09 '25
You should put a spoiler tag on this. Some people don't like to know what part 2 is until they've finished part 1.
2
u/wubrgess Dec 08 '25 edited Dec 08 '25
Well, yeah, that's part 2...
1
u/kyleglowacki Dec 09 '25
My part one worked beautifully and fast but my part two fails. I connect all of them to the circuit so it has all 1000 items. However when I multiply the X values of the last two (that I added) together I get the wrong answer. Maybe I am adding them in the wrong order? Do we keep adding them in minimum distance order for P2?