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Β§
- Position π