Advent of Code 2020 Day 6
I was sitting at my computer at 10:30 PM CST and slowly falling asleep, because of that, I decided I should just go to bed rather than try to stay up. I'm not sure if that was a good move or not, but I'll admit that I'm not a "quick solution" programmer, especially when it comes to these advent of code puzzles. My typical way to attack the Advent of Code puzzles is to turn the example for each part into a unit test so that I can validate the other working systems prior to attempting my actual input data. Perhaps this is why my solutions take longer, but it makes it easier for me to debug when I totally mess things up (which, by the way happens way more than I'd like it to).
Today's problem involved string processing to do some counts of characters in different ways, part one was to count the number of unique characters in a set of strings, part two was to count the number of common characters in a set of strings. While one is arguably easier than the other (unique is easier than common, generally) both are doing similar processing. The beauty with trying to use java streams is that part one was ESPECIALLY easy because I could just use String.chars().distinct().count()
to get the number of unique characters in a string. For the second part, I developed a method that took in the string, and returned a count of common characters for each of the split strings (split by -
) if that count was equal to the number of string, then the sum of those counts is returned. This was a fairly easy problem, just had a lot of work to fit my desire of using Java streams into some of the playbook. Oh, and since the reading was similar to day 4 I basically copied that file reading code in, with a modification to better support the part two which required each line to be separate.
It took me a while to complete part two (40 minutes according to my README and post image) and I mostly attribute that to likely fat-fingering my initial submission and not just re-running to see if it was correct. I spent probably 20-25 minutes on going through my counting code and going step-by-step through the process of validating results from each string that was pushed and adding some additional specific tests to validate the results were correct. I made no logic changes and submitted the answer again, and it seemed to work this time, so for whatever reason, I probably just fat-fingered the value, which I guess happens.
If you want to join my Advent of Code leaderboard, feel free to join with the code: 699615-aae0e8af
. I'll keep pushing to complete these challenges, because I find them to be fun and interesting.
Member discussion