Expand description

This is my solution for Advent of Code - Day 6: Wait For It

Today was solved with maths rather than brute force. The parsing is not much effort, but different for each part. part_1_line_parser and part_2_line_parser contain these differences, and the relevant one is passed to parse_input giving a list of Races.

find_count_of_winning_hold_times uses the quadratic formula to calculate the bounds, and therefore length of the winning range of seconds to hold before releasing the boat. find_product_of_races can be used for both parts, as the single race is unchanged by iter().product.

Structs

  • Race 🔒
    A race duration, with the distance to beat in that time

Functions

  • Calculate the range of seconds the boat’s button could be pressed for to exceed the current record for a race. Uses the quadratic formula to calculate the upper and lower bound, and return the size of the range of integers within those bounds.
  • Convert a list of races into the size of the range of hold times, and find the product of these as the puzzle answer.
  • Parse input from a line of durations and a line current record best times into a list of records. How to parse each line is abstracted to a line_parser for each part
  • Parse lines as multiple numbers separated by whitespace
  • Parse lines as a single number each
  • The entry point for running the solutions with the ‘real’ puzzle input.