advent_of_code_2024

Module day_6

source
Expand description

This is my solution for Advent of Code - Day 6: Guard Gallivant

parse_input captures a representation of the Lab and Guard. Guard::take_step is the key function for moving a guard, delegating to a bunch of helper functions in the same impl.

count_guard_positions is the solution to part one, using route_iter to generate the sequence of positions visited

count_obstructions_causing_loops is the solution to part 2, using is_loop along with reusing some of part 1.

StructsΒ§

  • Guard πŸ”’
    A Guard represented by their position and facing
  • Lab πŸ”’
    Represent a lab by its dimensions and a set of Positions with obstructions

EnumsΒ§

  • Direction πŸ”’
    The direction the guard is facing

FunctionsΒ§

  • Count the unique positions visited by the guard before she leaves the lab
  • Try adding obstacles to all locations on the guard’s route, and see which ones cause the guard to end up in an infinite loop
  • is_loop πŸ”’
    Will the guard end up in an infinite loop for the provided lab and starting position
  • parse_input πŸ”’
    Walk the input, building a set of obstructions and identifying the guard’s position
  • route_iter πŸ”’
    Return the list of positions and facings a guard follows until they leave the lab
  • The entry point for running the solutions with the β€˜real’ puzzle input.

Type AliasesΒ§