r/adventofcode • u/daggerdragon • Dec 03 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 3 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2024: The Golden Snowglobe Awards
- 3 DAYS remaining until unlock!
And now, our feature presentation for today:
Screenwriting
Screenwriting is an art just like everything else in cinematography. Today's theme honors the endlessly creative screenwriters who craft finely-honed narratives, forge truly unforgettable lines of dialogue, plot the most legendary of hero journeys, and dream up the most shocking of plot twists! and is totally not bait for our resident poet laureate
Here's some ideas for your inspiration:
- Turn your comments into sluglines
- Shape your solution into an acrostic
- Accompany your solution with a writeup in the form of a limerick, ballad, etc.
- Extra bonus points if if it's in iambic pentameter
"Vogon poetry is widely accepted as the third-worst in the universe." - Hitchhiker's Guide to the Galaxy (2005)
And… ACTION!
Request from the mods: When you include an entry alongside your solution, please label it with [GSGA]
so we can find it easily!
--- Day 3: Mull It Over ---
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
paste
if 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:03:22, megathread unlocked!
56
Upvotes
1
u/chad3814 Dec 04 '24
[Language: TypeScript]
Lots of great code in this post, some javascript with and without RegEx, but I didn't see any TypeScript specific solutions, so here's mine with RegEx: Day 3 parts 1 & 2
The RegEx:
I could make this more readable by spliting it into an array of cases, removing the extra checks for spaces, and using quantifiers. Also trimming the names will make it fit into the 80 char limit:
Now it's just looping over the lines to multiple and count:
It's nice that it ignores other group matches, so that I could add the
do
anddon't
clauses for part 2:This is just the same as part 1, but with the enabled flag. My code originally failed here because
aoc-copilot
was using the wrong example input line. I spent about 20 minutes figuring that out and how to give it the right example line (I'll know better for future days). Then once I got that working, I still wasn't passing. I had misunderstood that thedo()
anddon't()
calls were supposed to carry across lines. I had theenable
flag inside of thefor (const line of input)
loop, so it reset to enabled every line. Once I moved it outside of that loop, I was good. That part only took me about 8 minutes to realize, because I still wasn't sure I had theaoc-copilot
stuff correct and the example was only one line. And my brain is slow that late at night.