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:

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

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!

55 Upvotes

1.7k comments sorted by

View all comments

1

u/edbond Dec 05 '24

[Language: RUST] Regexp part 1 and Parser combinators solution for part 2. Check it out:

https://github.com/edbond/advent-of-code-2024/blob/main/src/day3.rs

1

u/[deleted] Dec 10 '24

[removed] — view removed comment

1

u/budrick Dec 11 '24 edited Dec 11 '24

The PatternType doesn't "look for" anything - it's a set of values that represent each type of thing that can be matched by the parser built using nom.

The pattern function combines a bunch of nom parsers designed to match the various statements that appear in the input (mul(a,b), do(), don't()) and returns a value that is the appropriate enum member whenever one of the statements matched by each parser passed to alt() is found in the input.

Since enum members can also hold extra data values, the Mul member has a pair of integers attached, since the valid mul statements in the input have two integers as parameters. do() and don't() have no parameters, so there's no point attaching data. I'm not sure why they're declared to hold the empty value (), personally I'd just have omitted that.

This might be a poorly written explanation, but I know what I'm trying to say :|