Today we begin the Advent of Code 2021. Every day we get a new problem to solve. Today’s problem was quite simple, you can find my code on my Github.
The Goals
Today’s goal is simple, get used to the data use, and challenges I’d like. My plan is to choose a different language, roughly, each day. For warming up to this I’ll jump between languages a lot in the first few days as my warmup.
We will also adjust our code to use input data in the exact form we downloaded it. You’ll note on the first input.txt you get the last line is blank. I’ll focus on making sure the data given for input to test can be processed correctly in the format we receive it.
I’ll also keep the example in my code the show since it adds only a few lines, that way it can be used without input data as an example. My thoughts behind this will be to have a way to look at my own code and run it without any input to remember what it does. As a reminder, I suffered a TBI. The line count can always be less, I’ll just keep myself happy with readability and format of code shared so you can also read it easily.
I will have my code up on Github, and also shown here in images. You’re meant to challenge yourself, so it’s on your shoulders, don’t copy me: challenge yourself! I will show my code here in the blog post in images. Students might like it showing them different ways to think with their programming problems.
I wont share the final solution in any step, please trust me: my solution gave the correct answer(s). Try it yourself, try do it in a different way compared to me, make this challenge a fun task for you as a fellow programmer!
Step 1
Step 1 required a simple method for counting depth increases. For this we did the minimal .Net 6 C# solution.
As you can see my code can be 6 lines shorter above, I only point it out here once so anyone that follows can see I just leave samples and readability in for my own fun!
Line 4 to 10 are my favorite section, you can put the contents into a single line. File IO being split leading to Linq to data parsing to give a single array we can use.
Step 2
Step 2 is a simple thought on how to process data in a slightly different way, as in to get know how often it has segments which have significantly lower depths.
The one problem I had was remembering python as a whole, it’s been years since I used it last. Nothing significant though, this completes today’s challenge!
Afterthoughts
For the start of these I’ll have afterthoughts related to which languages I’ll keep as uses for these challenges.
Today’s C# and Python are ones I will reuse in the future challenges! Note, this is what I feel like for my choices since it fit in my Full Stack requirements as a Systems Engineer.
Future languages are C, C++, F#, and JavaScript. I feel I might drop one, at some point, but I’m already having some fun with the refreshers.