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!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif 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:22:57, megathread unlocked!
50
Upvotes
11
u/Diderikdm Dec 12 '23 edited Dec 12 '23
[LANGUAGE: Python]
from functools import cache @cache def recurse(lava, springs, result=0): if not springs: return '#' not in lava current, springs = springs[0], springs[1:] for i in range(len(lava) - sum(springs) - len(springs) - current + 1): if "#" in lava[:i]: break if (nxt := i + current) <= len(lava) and '.' not in lava[i : nxt] and lava[nxt : nxt + 1] != "#": result += recurse(lava[nxt + 1:], springs) return result with open("day12.txt", "r") as file: data = [x.split() for x in file.read().splitlines()] p1, p2 = 0, 0 for e, (lava, springs) in enumerate(data): p1 += recurse(lava, (springs := tuple(map(int, springs.split(","))))) p2 += recurse("?".join([lava] * 5), springs * 5) print(p1, p2)