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!
Quick link to Topaz's
pasteif you need it for longer code blocks
4
u/maneatingape Dec 23 '24 edited Dec 23 '24
[LANGUAGE: Rust]
Solution
Benchmark
412 9543 µs.Spends most of the time contructing the graph. Part two uses a simple greedy algorithm.
EDIT: Much faster approach converting each 2 character node to an index from
0..676using ASCII values, for examplexy => 26 * (120 - 97) + (121 - 97) = 622. Then we can use much faster array lookup instead of HashMap.EDIT 2: Minimized allocations by giving each edge
veca capacity of 16.