Skip to content

The Advent of Code 2020 Day 19 log, Regex from hell

Posted in Advent of Code

Hello, there and welcome to my Advent of Code 2020 Day 19 cruise log. Today was quite unpleasant and I had a big role in that. Even though I should know by now to follow my instincts on what feels simpler I keep going for the dunk. And time and time the problem dunks on me, I thought yesterday was bad but today was something else.

If only I put some more faith in my ability to write regular expressions none of this would have happened. But nope, I just had to go and try to create my own language processor to interpret any possible combination of messages to validate. Oh yes, today we had to parse a bunch of data that we would turn into a language and messages to validate against it. The sort of thing you get if you do natural language processing but with some “a” and “b”.

This whole morning I could feel how close to the solution I got, I could even touch it without knowing white why it didn’t work. The first part didn’t pose any issue, slow implementation for sure but all good within an hour. The second part however, this is where trouble began.

Naturally, I did use the language I built for part one to implement part two with a simple constraint. Not so simple looking back at how long I spent on it but pretty trivial when I see my final solution. Which adds to the pain of taking so long.

I kept on going back and forth reimplementing everything from scratch over and over again. Once using my custom processing language, then trying to create a giant regular expression. Back and forth and back and forth. With little to no results. Test wouldn’t pass. I felt hopeless, and after about six hours, my girlfriend asked me to join her for brunch which I did after a few minutes.

We spent the bulk of the day together but that problem didn’t leave my mind. I kept thinking about it over and over, almost obsessively. Maybe the Advent of Code is taking over my mind, maybe by the end of it, I won’t have much left of it. Is this cost too great to bear, shall I gamble my sanity? Am I gambling my sanity for a contest which is as much good to learn algorithms, patterns and languages as it feeds one’s ego? So many questions, so little time to answer. One thing is for sure, it is about 10 pm in London now. So far, I have been up for about eighteen hours. I definitely need some sleep especially as day 20 lurks around the corner. Hopefully, tomorrow will be better but I doubt it. To better days my friends.

2020/12/29 EDIT: I’m realising now that I forgot to mention how I went about it in the end, that’s how tired I was. I just wrote a big regex builder. And expanded the updated rules 8 and 11 using regex language into the monstrosities below:

rulesRegex["8"] = "42 +"
rulesRegex["11"] = "42 (?: 42 (?: 42 (?: 42 (?: 42 (?: 42 (?: 42 (?: 42 (?: 42 (?: 42 (?: 42 31 )? 31 )? 31 )? 31 )? 31 )? 31 )? 31 )? 31 )? 31 )? 31 )? 31"

Thank you for reading my Advent of Code 2020 Day 19 cruise log, I will see you tomorrow, maybe. In the meantime, you can check out my Go Cloud series about building and deploying a Golang app to AWS. Also, I will push my code on Github at CodingNagger/advent-of-code-2020. Feel free to check it out but not before you’ve done the challenge yourself. Bye!

Photo by Ian Panelo from Pexels

Be First to Comment

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    %d bloggers like this: