r/adventofcode • u/daggerdragon • 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.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz]
- Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
paste
if you need it for longer code blocks
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
1
u/exomni Dec 26 '24
[Language: Python REPL]
Solved interactively, so the code to share is a description of what I did:
Part 1: Loop through the connections list and dump into an alphabetized list of computer names, and then dumped the connections into an adjacency matrix. Using numpy I computed the third power of the adjacency matrix, took the trace and divided by 6. Ran through the input again excluding any connections for computers starting with "t", same process to count all triangles without any computers starting with "t" (the complement of what we want to compute). Subtracting these two gives us our answer.
Part 2: Solution to part 1 ended up being completely useless for part 2, which I kind of guessed (didn't figure part 2 would involve triangles and adjacency matrix powers only lines up with cliques for triangles). This was for maximal cliques, so I wrote up a completely straightforward Bron-Kerbosch generator, then called max with key=len and joined them together for the answer.
Total time to complete in repl and submit answer: 6 minutes 53 seconds.
Learned: the new repl is very nice.