Class SolutionDay6

java.lang.Object
com.expedient.adventofcodejade.BaseSolution
com.expedient.adventofcodejade.solutions.year2024.SolutionDay6

public class SolutionDay6 extends BaseSolution
  • Constructor Details

  • Method Details

    • doStep

      public static Pair<Coordinate,Direction> doStep(Grid<Character> grid, Coordinate location, Direction direction, Coordinate obstruction)
      Identify the next tile in front of the guard. If the next tile is OOB, raise an exception. If the next tile is an obstruction, turn clockwise. Otherwise, move forward into the tile.
      Parameters:
      grid - the Grid from the input
      location - the current location of the actor
      direction - the actor's direction
      obstruction - the coordinates of a placed obstruction
      Returns:
      a Pair containing the new coordinate and the new direction
    • getAllVisitedLocations

      public static Set<Coordinate> getAllVisitedLocations(Grid<Character> grid, Coordinate location, Direction direction)
      Continuously performs doStep, adding each Coordinate visited to a Set. Once the actor moves OOB, break out of the loop and then return the Set of visited Coordinates.
      Parameters:
      grid - the Grid from the input
      location - the starting actor Coordinate
      direction - the starting actor Direction
      Returns:
      the Set of visited Coordinates
    • detectLoop

      public boolean detectLoop(Grid<Character> grid, Coordinate obstruction)
      Given a grid and a designated obstruction, continuously performs Steps, adding the actor's visited coordinates and direction as Pairs to a Set. This goes on until the actor goes OOB (which means no loop), or the actor's current direction and location are found in the Set, which means they must have looped.
      Parameters:
      grid - the Grid from the input
      obstruction - a location that will be treated as a wall
      Returns:
      whether the grid and obstruction result in a situation that causes a loop
    • partOne

      public Integer partOne(PuzzleInput input)
      Finds the number of unique locations visited by the actor, based on the original map
      Specified by:
      partOne in class BaseSolution
      Parameters:
      input - the PuzzleInput to be used for the solution
      Returns:
      the number of unique locations
    • partTwo

      public Integer partTwo(PuzzleInput input)
      Finds the number of locations where an obstruction may be placed on the grid to cause the actor to move in an infinite loop
      Specified by:
      partTwo in class BaseSolution
      Parameters:
      input - the PuzzleInput to be used for the solution
      Returns:
      the number of potential obstruction locations