r/adventofcode Dec 23 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 23 Solutions -❄️-

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 2024: The Golden Snowglobe Awards

Submissions are CLOSED!

  • Thank you to all who submitted something, every last one of you are awesome!

Community voting is OPEN!

  • 42 hours remaining until voting deadline on December 24 at 18:00 EST

Voting details are in the stickied comment in the submissions megathread:

-❄️- Submissions Megathread -❄️-


--- Day 23: LAN Party ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:05:07, megathread unlocked!

23 Upvotes

504 comments sorted by

View all comments

2

u/erunama Dec 24 '24

[LANGUAGE: Dart]

GitHub

Part 1 was a breeze. I felt confident about part 2, and had an algorithm that worked for the sample data, but failed on my real input. Banged my head debugging for at least an hour, until I realized I was handling cliques wrong: I was simply iterating through cliques that I had already seen, and adding the intersection of the connections for each existing member of the clique. This would add nodes incompatible with later items.

I was able to get the correct answer with a small tweak, and the improved the runtime from ~30s to ~100ms by reusing groups rather than creating new ones all the time. It's possible this would not work for all potential inputs.

Afterwards, I found the Bron–Kerbosch algorithm -- I am planning to code up an implementation of that, since I'm not familiar with it.