r/adventofcode • u/daggerdragon • Dec 22 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 22 Solutions -❄️-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
Community fun event 2023: ALLEZ CUISINE!
Submissions megathread is now unlocked!
24 HOURS remaining until the submissions deadline TONIGHT (December 22) at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Your final secret ingredient of this Advent of Code season is still… *whips off cloth covering and gestures grandly*
Omakase! (Chef's Choice)
Omakase is an exceptional dining experience that entrusts upon the skills and techniques of a master chef! Craft for us your absolute best showstopper using absolutely any secret ingredient we have revealed for any day of this event!
Choose any day's special ingredient and any puzzle released this year so far, then craft a dish around it!
Cook, bake, make, decorate, etc. an IRL dish, craft, or artwork inspired by any day's puzzle!
OHTA: Fukui-san?
FUKUI: Go ahead, Ohta.
OHTA: The chefs are asking for clarification as to where to put their completed dishes.
FUKUI: Ah yes, a good question. Once their dish is completed, they should post it in today's megathread with an [ALLEZ CUISINE!] tag as usual. However, they should also mention which day and which secret ingredient they chose to use along with it!
OHTA: Like this? [ALLEZ CUISINE!][Will It Blend?][Day 1] A link to my dish…
DR. HATTORI: You got it, Ohta!
OHTA: Thanks, I'll let the chefs know!
ALLEZ CUISINE!
Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!
--- Day 22: Sand Slabs ---
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/mtpink1 Dec 22 '23
[LANGUAGE: Python]
Code, Livecoding video
This was a fun one! My solution used the fact that we can iterate over the blocks in order of minimum z coordinate when computing their fallen positions. I used a
height_map, which stores the maximum height and block index at each(x, y)position and it iteratively updated at the blocks are processed.As I computed the final positions of the falling blocks, I populated two maps,
supportsand the inverse mappingsupported_by, which track for each block the blocks that it supports and it is supported by. These two maps then allowed me to easily compute the solutions for parts 1 and 2.For part 1, my logic was that a block can be disintegrated if each block that it supports is supported by at least two blocks (i.e. once disintegrated it will still be supported).
For part 2, I again iterated over each of the blocks and created a set
will_fall, initially containing the index of the block to be removed. I then iterated over each of the blocks above the block being tested and checked if they were supported by only blocks in thewill_fallset. If so, I added it to the set. Since I used asetas the value for thesupported_bymap, this operation was made super simple: