Class SolutionDay6
java.lang.Object
com.expedient.adventofcodejade.BaseSolution
com.expedient.adventofcodejade.solutions.year2024.SolutionDay6
-
Constructor Summary
ConstructorsConstructorDescriptionSolutionDay6(PuzzleInput input, PuzzleInput sampleInputOne, PuzzleInput sampleInputTwo) -
Method Summary
Modifier and TypeMethodDescriptionbooleandetectLoop(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.static Pair<Coordinate, Direction> doStep(Grid<Character> grid, Coordinate location, Direction direction, Coordinate obstruction) Identify the next tile in front of the guard.static Set<Coordinate> getAllVisitedLocations(Grid<Character> grid, Coordinate location, Direction direction) Continuously performs doStep, adding each Coordinate visited to a Set.partOne(PuzzleInput input) Finds the number of unique locations visited by the actor, based on the original mappartTwo(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 loopMethods inherited from class com.expedient.adventofcodejade.BaseSolution
getInput, run
-
Constructor Details
-
SolutionDay6
-
-
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 inputlocation- the current location of the actordirection- the actor's directionobstruction- 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 inputlocation- the starting actor Coordinatedirection- the starting actor Direction- Returns:
- the Set of visited Coordinates
-
detectLoop
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 inputobstruction- a location that will be treated as a wall- Returns:
- whether the grid and obstruction result in a situation that causes a loop
-
partOne
Finds the number of unique locations visited by the actor, based on the original map- Specified by:
partOnein classBaseSolution- Parameters:
input- the PuzzleInput to be used for the solution- Returns:
- the number of unique locations
-
partTwo
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:
partTwoin classBaseSolution- Parameters:
input- the PuzzleInput to be used for the solution- Returns:
- the number of potential obstruction locations
-