Hello, there and welcome to my Advent of Code 2020 Day 6 cruise log. Today’s challenge felt like one of these interview questions you and play with on Hackerrank, the easy ones. Maybe Eric Wastl took pity on us because it’s Sunday and some of us woke up before 5 am to take part. Or, he wants to give us a false sense of confidence before dunking on us when the second week begins. Week 2 is usually when you start losing people as challenges get trickier. I shall let TDD guide me through it to make it all the way into the last week like last year.
As one would expect from the previous couple of days, I did write my tests first. This time I only needed the example entries considering this was an easier problem to tackle.
First part was pretty swift, some easy counting stuff. Basically we had groups of entries and we had to count unique answers for each groups. This screamed at me to use a map. Obviously the map’s key is the answer then the value doesn’t matter as our map there is used as a set. I used bool but you can put anything you want in there.
When it came to part two, we needed to change the counting logic from taking all unique answers from a group to count where all the group members answered yes. I copy-pasted the first part and only needed to change the counting logic.
Wait, actually I also changed my map type. As it turns out since I needed to count answers where everyone answers by the positive I kept count of votes for each question. From there you eliminate the answers where the count doesn’t match the amount of group member. Straightforward enough. I guess by now we’re counting stars.
Thank you for reading my Advent of Code 2020 Day 6 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!