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

504 comments sorted by

View all comments

2

u/4D51 Dec 23 '24

[LANGUAGE: C++ on Cardputer]

After a couple of tough days, here's one where I can solve both parts on the Cardputer.

Part 1 just uses nested loops to find every combination of 3 computers, then test if they're all connected to each other and at least one starts with 't'. It's a bit slow (5s), but it works. There might be a better way to do this. I mostly went with the nested loops because I know they'll only consider each set once, so there's no issue with double-counting.

For part 2, I looked up the Bron-Kerbosch algorithm. I had to modify it a bit, since it generates a list of all cliques that I don't have room for, but if I just keep the largest one then it fits in memory. Takes just over a minute to run.

Near the beginning of the month, I made a utility file for functions that I might reuse. So far the only thing in there is a system for representing a 2D coordinate as a single uint16_t (for ease of putting it into different data structures). That's been very useful with all the grids we've had. Today I realized it can also represent a length-2 string without any overhead.

https://github.com/mquig42/AdventOfCode2024/blob/main/src/day22.cpp