Skip to content

The Advent of Code 2020 Day 2 log, password pains

Posted in Advent of Code

Hello everyone and welcome to my Advent of Code 2020 Day 2 entry. The simplicity of today’s problem got trumped by some knowledge gap of Golang I am still to fill. Today I managed to make this gap a little bit smaller. Figuring how to convert strings to rune arrays (basically chars arrays) took me on a DuckDuckGoing journey which took away some precious minutes. Eventually, I landed on the Programming guide website which I never heard about before. Turns out that’s out you do it that way:

chars := []rune(stringToConvert)

I do recall now that I saw it that the Golang course I took mentioned something about most type conversions working that way. However, coming from more traditional languages like Java or C# it is a trickier format to remember.

I woke up at 4.20, again, but this time I used the free time to stretch, put on some music on Spotify and indulge myself with a glass of water. My brain’s foggy state didn’t help but hopefully, as I’m building this habit, it will get better over time. Only need to keep that up for the first week then problems get too complicated for it to only be a speed coding challenge.

Once that rune array conversion hurdle passed, I implemented the first part pretty easily. The unit test using the example given passed with flying colours. Or so I thought. I faced the dreaded wrong answer screen for the first and hopefully last time of this Advent of Code.

Since my default unit test was useless, I introduced some debugging lines to figure what was wrong. As it turns out, I introduced the oldest bug in the book. The inverted comparison condition on my min/max value check. Somehow I wrote code that checked my test value being below the minimum value. Felt real dumb for a second as I even had a unit test for it.

As soon as I spotted the issue, I added a unit test to enforce the correct behaviour and ran my input through the code again. It passed! From there, I was on a roll and pretty much instantly sorted the second part. Fast enough for that bug-hurt pride of mine but not fast enough to even make it to the top 4000 worldwide. At least it was done.

Thank you for reading my Advent of Code 2020 Day 2 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 so feel free to check it out but not before you’ve done the challenge yourself. Bye!

Photo by Anna Tarazevich 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: