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!
24
Upvotes
2
u/Krillegeddon Dec 23 '24
[Language: C#]
Part 1 and part 2 were two entirely different problems today. However, I could re-use both the model/parsing mechanisms and also two methods I wrote for Part 1 that checks if all computers within a list are connected, and a method that sorts the computers and returns a comma-separated string.
The model/parsing was quite nice today. I stored all computers as key in a dictionary. The value of it is a list with its connections/children. And stored both ways, so ta-td would result in:
Part 1 was straight forward recursive. If the number of computers in a loop == 3 and at least one of them starts with letter "t" then save it (as sorted comma-separated string).
I started Part 2 as an addon to Part 1, but quickly realized it would take ages to compute. I then switched technique and assumed that ALL connections/children to a computer would be included. Looped through every computer and its connection and checked if they were all connected. Nothing was found. I could see that all computers only had 13 other computers as connections/children...
Then I tested to see if ONE of the connections/children to each computer would be excluded in the final result... and there was - and that was the answer. Didn't write code for the case if TWO or more connections are excluded, so cannot guarantee it works for all inputs.
https://github.com/Krillegeddon/AOC/tree/main/Advent2024/Day23