Day 6, part 2
Day 6 challenge of the mighty Advent of Code 2024
Created at:
Last updated:
Table of Contents
Introduction
Once again, let me welcome you to the next Advent of Code puzzle. This is a part 2 of day 6 and this article is a continuation of the Day 6, part 1, so please read it first before you start this one. This part of the challenge is available only when you successfully finished the part 1. The second part of the challenge is described under section here.
What is the new problem
Well, it came out that the input data is not listing couple of separate races, but this is just one race (one time and one distance), but the numbers just have some spaces in-between. So lets look at the test data:
With what we know now, these numbers supposed to be read as and . Looking at the website for the solutions to this example we can see that the range starts from until and the final count of all solutions is .
Solution
The solution is pretty simple and it in the most part reuses all those functions we had before. I just had to write a new data parsing function. Please replace input data from the file with the test data. Here is the whole new code to get the.
If we run this piece of the code we will see:
And this is what we were looking for! Let's save it!
Final result
Now we can switch back to the input being read from the file and we can make the final run of our code.
We now submit this number on the page and we can see our favorite message.
Lets commit all the changes.
This is all if it comes to day 6. Pretty easy huh? I hope you enjoyed it and see you in Day 7, part 1