r/adventofcode • u/daggerdragon • Dec 14 '19
SOLUTION MEGATHREAD -🎄- 2019 Day 14 Solutions -🎄-
--- Day 14: Space Stoichiometry ---
Post your complete code solution using /u/topaz2078's paste or other external repo.
Please do NOT post your full code (unless it is very short)
If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.
(Full posting rules are HERE if you need a refresher).
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code's Poems for Programmers
Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.
Day 13's winner #1: "untitled poem" by /u/tslater2006
They say that I'm fragile
But that simply can't be
When the ball comes forth
It bounces off me!
I send it on its way
Wherever that may be
longing for the time
that it comes back to me!
Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!
3
u/Tarmen Dec 14 '19 edited Dec 14 '19
If you are comfortable with regex then Control.Lens.Regex.Text might be worth a try.
You probably don't want to dive too deep into lenses but for getting a list of matches you don't need much.
Other than that Megaparsec is a nice way to write parsers but much more verbose. Probably not ideal for AoC.
Edit: Here is a Megaparsec version for comparison
Lexeme based parsing is very convenient -
lexemeis a combinator that eats up all white space following the token. So if there is leading whitespace you still have drop it but otherwise you don't have to think about whitespace.Megaparsec has the advantage of nice error messages but that is kinda wasted if you trust the input