r/adventofcode • u/daggerdragon • Dec 16 '22
SOLUTION MEGATHREAD -π- 2022 Day 16 Solutions -π-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
A request from Eric: A note on responding to [Help] threads
Signal boost: Reminder 2: unofficial AoC Survey 2022 (closes Dec 22nd)
πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
UPDATES
[Update @ 00:23]: SILVER CAP, GOLD 3
Elephants. In lava tubes. In the jungle. Sure, why not, 100% legit.
I'm not sure I want to know what was in that eggnog that the Elves seemed to be carrying around for Calories...
[Update @ 00:50]: SILVER CAP, GOLD 52
Actually, what I really want to know is why the Elves haven't noticed this actively rumbling volcano before deciding to build a TREE HOUSE on this island.............
High INT, low WIS, maybe.
[Update @ 01:00]: SILVER CAP, GOLD 83
Almost there... c'mon, folks, you can do it! Get them stars! Save the elephants! Save the treehouse! SAVE THE EGGNOG!!!
--- Day 16: Proboscidea Volcanium ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
Include what language(s) your solution uses
Format code blocks using the four-spaces Markdown syntax!
Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
19
u/jonathan_paulson Dec 16 '22 edited Dec 16 '22
C++, 41/412. Video. Code. Explanation video. My C++ code solves both parts in 3 seconds.
Hardest advent of code problem ever? My video is 2 hours long!
I'm proud of my solution to part 2. I thought of part 1 as a dynamic programming problem: "given that I am at position P, with a set V of valves opened, and T minutes left, how many points can I score?" This has state space 50*2**15 * 26 ~ 42 million, which is doable.
But what do you do for part2? Just add 1 more dimension: "am I the first player or not?" Then once you're done, if you're the first player, just reset to the second player's turn (so they have 26 minutes and start at "AA"), but *don't* reset the opened valves, since you can't both score for the same valves. This only inflates the state space by a factor of 2! I tried for a long time to find a solution where both players are acting "in parallel" before finally realizing I could just think about them acting in serial instead. Instead of imagining you and the elephant playing at the same time, imagine you go first and then the elephant goes (but he can't open any valves you already opened). Exactly the same problem! Also, this would easily handle the case of multiple elephants!