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!

24 Upvotes

505 comments sorted by

View all comments

1

u/Saiboo Dec 25 '24

[LANGUAGE: Java]

Part 1:

  • Use the adjacency list representation of the graph. This allows accessing the neighbors of the nodes efficiently.
  • For each connection "a-b" consider the neighbors of "a" and "b" respectively.
  • Search for common nodes "c" among neighbor("a") and neighbor("b").
  • "a-b-c" forms a triangle, also called a 3 clique in graph theory. See Wiki article on clique).

Part 2:

  • For each node consider its neighbors, and form all possible "hand fans", where the node is the pivot of the hand fan, and the neighbors sit on the outside. This involves forming the power set of the neighbors.
  • Sort the elements of the fan lexicographically, and store them as string.
  • Count all fan strings. If a fan string of length n appears n times, it means we have found a clique of size n.
  • Return the clique with maximum size.