Expand description
This is my solution for Advent of Code - Day 14: Restroom Redoubt
parse_input uses Robot::from_str to build up a list of Robots.
total_safety_factor_after_steps is used to solve part 1, delegating to simulate_robots and
total_safety_factor which groups robots into Quadrants and calculates the product.
guess_tree_seconds uses iterate_seconds to loop through all the possible positions of the robots, find
the one with the lowest total_safety_factor as a proxy for the robots clustering into a tree.
render_robots can be used to show the robotβs current position visually
StructsΒ§
- Robot πA robot patrolling the grid
EnumsΒ§
- Quadrant πThe four areas of the grid used to calculate the
total_safety_factor
FunctionsΒ§
- guess_
tree_ πseconds Guesses which second shows the image by finding which has the lowesttotal_safety_factor - iterate_
seconds πAn iterator over the unique arrangements of the robots on the grid - parse_
input πTurn the input file into the internal representation - partition_
position πFor a given position, calculate which quadrant of the grid it is on. If the position is on one of the centre lines of the grid, this returnsNone - render_
robots πRender the position of the robots on an ascii art grid. - The entry point for running the solutions with the βrealβ puzzle input.
- simulate_
robots πCalculate the position of all robots afterstepsseconds - total_
safety_ πfactor The product of the count of robots in each of the four quadrants - The solution to part 1 - simulate
stepsseconds and then get thetotal_safety_factorof the new positions.