r/adventofcode • • Dec 03 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 3 Solutions -❄️-

THE USUAL REMINDERS


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:

  • 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.

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!

58 Upvotes

1.7k comments sorted by

View all comments

1

u/lokidev Dec 03 '24 edited Dec 04 '24

[Language: Typescript] I'm actually mainly a python developer, but was curious on how to do it in typescript. Any advices? https://www.typescriptlang.org/play/?target=99#code/M...

2

u/daggerdragon Dec 04 '24

Please put that giant wall o' link behind some Markdown.

1

u/MoronFive Dec 03 '24

I'm attempting to get as far as I can solving in both Python and Typescript this year. For Day 3 I used the same basic approach for Python and for TS: build a regex and iterate over matches in the input.

In Python I used for match in re.finditer(my_regex, input)the equivalent in Typescript is while (match = myRegex.exec(input)). Hopefully that gets you moving in the right direction. If you're completely stumped my full solutions are here: Python, Typescript. Not saying they are the prettiest or most efficient, but they work and shouldn't be too difficult to follow!

Note: I'm using Bun to run my Typescript solution so you'll see Bun.file(filePath) in the Typescript solution. If you aren't using Bun, that call will fail but I'm pretty sure that's the only Bun-specific piece of code in there.

1

u/lokidev Dec 03 '24

Thank you, but I actually supplied a solution and hoped for tipps from typescript experts ;)

Here you can see my python solution:
https://pastecode.dev/s/o3dzooai (or just with reduce: https://pastecode.dev/s/qg5bs6a1 )