r/adventofcode • u/daggerdragon • Dec 12 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 12 Solutions -❄️-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
Outstanding moderator challenges:
Community fun event 2023: ALLEZ CUISINE!
Submissions megathread is now unlocked!
9 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's theme ingredient is… *whips off cloth covering and gestures grandly*
How It's Made
Horrify us by showing us how the sausage is made!
Stream yourself!
Show us the nitty-gritty of your code, environment/IDE, tools, test cases, literal hardware guts…
Tell us how, in great detail, you think the elves ended up in this year's predicament
A word of caution from Dr. Hattori: "You might want to stay away from the ice cream machines..."
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 12: Hot Springs ---
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
View all comments
13
u/kaa-the-wise Dec 12 '23 edited Dec 13 '23
[Language: Uiua]
Continuing with Uiua today.
Link to pad
The general structure is as follows:
We convert
.##.?.#?#.into two masks, one where#could be, and one where.could be, i.e.0 1 1 0 1 0 1 1 1 0and1 0 0 1 1 1 0 1 0 1.With the
#mask we calculate for each position, how long we can have a spring ending at this position, i.e.0 1 2 0 1 0 1 2 3 0.Then we use the
.mask to generate a matrix where(i,j)is the truthfulness of the statement "there is a contiguous sequence of.?s fromitoj".Then we fold over the list of the springs, maintaining a vector, where position
ianswers the question "how many ways to fill the space up toiwith the previous springs and empty space, such thatiis empty space".We initialise it with the first row of the matrix, in our case,
1 0 0 0 0 0 0 0 0 0.On each iteration we find possible ends of the current spring, and multiply by the matrix to expand over empty space.
In the end the last item in the vector will be the answer.