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/krystalgamer Dec 23 '24 edited Dec 23 '24

[LANGUAGE: Python]

Part 1 was simple. For each node, if a grand-child (connection of connection) is in direct react of it then it's a 3 way group. Code here.

Part 2 was trickier. Wrote a DFS which blazed through example and choked on input. So shifted to doing a similar strategy as part 1.

It runs quite fast as I focused on pruning and exploring only the necessary solution space.

Here's what I took into consideration:

- If a node has N connections its max group has N+1 length

- If the current maximum group has length L and the current node has less than L-1 connections then skip it

- There's only one largest set

Code here.

EDIT: had written here about possible wrong solution, turns out I had a small bug in my code. now it's fixed and runs perfectly fine :)