Advent Of Code
6th December 2023
2023 - Day 6
Wait For It
Today's challenge is a toy boat race that's speed depends on how long you charge it up at the start of the race. The longer you charge for, the less time to actually race. We need to find out how many different charge times will beat the known record distance.
As usual, I first parse out our data with a strpos and regex to get our times and distances.
I could then run through each time and do a little math to find our possible combinations of hold time and distance travelled.
If the distance requirement was met, I counted that against this race.
The last part was to multiply the counts from each race, which utilised a useful array function in PHP
Part Two was also quite straight forward.
This time we had to consider there was a "kerning problem" where our values
44 82 69 81 were actually a single number
I decided to add a little code in the middle to implode the numbers, reset the array to a single entry, and I didn't have to rewrite anything else.
All in all, much more enjoyable than yesterday!
My full responses are found on GitHub