advent_of_code_2024

Module day_14

source
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Β§

  • Guesses which second shows the image by finding which has the lowest total_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
  • 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 returns None
  • 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 after steps seconds
  • The product of the count of robots in each of the four quadrants
  • The solution to part 1 - simulate steps seconds and then get the total_safety_factor of the new positions.

Type AliasesΒ§

  • Position πŸ”’
    A robot’s position on the grid (row, column)
  • Velocity πŸ”’
    The speed a robot is travelling along each axis (row, column)