Advent of Code 2023 - Day 6Wait For It
| Problem statement | Source code | Tags: Mathematics
Part 1
If I held the button for milliseconds to reach speed , then the distance traveled in milliseconds is . I need this to be more than . Rearranging gives , which means I can't win if . Otherwise, I need . I just need to count the integers in this range.
The number of integers in the exclusive range is . Why? Because and are the integers outside the range.
Part 1 is the product of applying this function to each row.
Part 2
Because we aren't doing simulations, just calculations, making the input larger doesn't change anything. Previously it was wins <- apply(parsed_data, 1, winning_vals); now it's wins <- winning_vals(list(times = times, distances = distances)).