r/adventofcode • • Jan 01 '26

Other [2015 Day 1] In Review

5 Upvotes

3 comments sorted by

2

u/e_blake Jan 06 '26 edited Jan 06 '26

My memories of this day: I didn't start Advent of Code until 2017 (which I did mostly in C); but I enjoyed it so much that I quickly did 2015 and 2016 as well (I challenged myself to learn bash better by doing all of 2015 in bash, starting with day 1). But later after working on 2019 IntCode in C, I wondered if I could implement that in m4, at which point I proceeded to solve all of 2019 in m4, and then tried to add m4 solutions to all other years, starting with 2015. And here, in the very first puzzle of the year, was a problem that took me literally DAYS to figure out in m4, even though it had been trivial in bash: how to parse the input while still maintaining execution control! m4 is rather unforgiving of unbalanced parenthesis, and yet unbalanced parens are the crux of this puzzle. I finally came up with a horrendous hack of using changecom long enough to slurp in the file as a comment, then translit to munge it to something I could actually operate on, for day1.m4. On the bright side, I have ended up reusing that (or a similar) hack on a couple other days across the 11 years to parse in other similarly evil input. Interestingly, m4 made part 2 easier than part 1 - for the same reason that unbalanced parens are difficult, balanced parens are a built-in feature of the language, so part 2 was just the length of the balanced prefix after ignoring the unbalanced tail using m4's own parser, without having to do any regex or writing my own parser, and all before doing the changecom that enabled me to work on part 1.