Advent of Code 2024 - Day 1
Historian Hysteria
Written December 20th, 2024 | Attempted December 3rd, 2024
Tags:Advent of CodeC++
So from what I understand, the problems on the first day are typically “easy,” just to warm up people to the format I think. Guess that makes sense since this solution is relatively straight forward.
# Part 1
There's a lot of text but it basically boils down to the following steps:
- Read in the file (arguably the biggest part).
- Sort the two lists provided in the file.
- Find the first differences and compute the sum of them.
Here's an example of the input file, where the first list is on the left and the second list is on the right:
In C++, the code boils down to this:
And because I'm an epic C++ programmer, here's the same thing but using ranges:
# Part 2
Part 2 is a bit more involved but it's still relatively simple. Basically:
- Read in the file (again).
- For the first unique instance of a number in the first list, count the number of occurrences in the second list. The base “similarity score” is the product of the unique number and the number of occurrences.
- For every repeat occurrence in the first list, the score increases by the product computed before.
- Then compute the sum of the similarity scores.
Here's the code:
Again, pretty simple stuff that's good for a warm-up. Though, I've heard the problems get harder as the days go on. Here's hoping I can get past day 5 lmao.