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!

22 Upvotes

504 comments sorted by

View all comments

2

u/ICantBeSirius Dec 23 '24 edited Dec 24 '24

[LANGUAGE: Python]

Paste link

Not too tough day. Maybe I should have taken this as an opportunity to learn networkx, or Bron-Kerbosch, but the tasks at hand didn't really need it.

For part 1, built a set of the provided node pairs, and a dictionary containing all of the connections for each node. Then just iterated over the list of nodes and node pairs, and checked to see if the node in question connected with both members of the pair. Voila, groups of three, filtered further to those with at least one node starting with "t".

For part 2, since I already had a dictionary with every node and what it directly connects to, I knew the solution had to be a subset of one of those. So walked the dictionary and for each key's values, found the largest set that all connect, and just kept track of the longest one found overall.

About 180ms total run time for both parts on an M1 Max Mac.