Advent of Code: Elegant Solution to a Stateful Parsing Problem

2025-04-09

The latest Advent of Code puzzle involves interpreting `do()` and `don't()` instructions that enable or disable the contribution of `mul` instructions to a sum. Regular expressions struggle with this statefulness, as they recognize stateless regular languages. The author uses a parser-based solution, lifting it into a state transformer to create a stateful parser. This parser efficiently handles `do()`, `don't()`, and `mul` instructions, processing roughly 1MB of input in 0.12 seconds—a significant improvement over a regex-based approach.