Class SolutionDay16
java.lang.Object
com.expedient.adventofcodejade.BaseSolution
com.expedient.adventofcodejade.solutions.year2024.SolutionDay16
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSorts two Coordinate, Integer, Direction triplets based on the Integer value (score) in contained in eachstatic final recordRepresents parsed grid (maze), starting point, and ending point derived from Puzzle Input -
Constructor Summary
ConstructorsConstructorDescriptionSolutionDay16(PuzzleInput input, PuzzleInput sampleInputOne, PuzzleInput sampleInputTwo) -
Method Summary
Modifier and TypeMethodDescriptionfindAllMazeSolutions(Grid<Character> grid, Coordinate startPoint) Use Dijkstra's Algorithm to find all possible shortest paths through the maze.static List<Pair<Coordinate, Integer>> getNeighbors(Grid<Character> grid, Coordinate current, Direction currentDirection, Set<Pair<Coordinate, Direction>> visited) Given the Grid, current position, current direction, and a Set of previously visited Coordinate, Direction pairs, find neighboring Coordinates and their associated weights (how much traversing to them will impact the score)static booleanGiven a Character, returns true if the character is considered traversable in the mazepartOne(PuzzleInput input) Find one of the shortest possible paths through the maze with the given parameters, and then calculate its score.partTwo(PuzzleInput input) Find all shortest paths through the maze, and then figure out how many coordinates (seats) lie along those pathsMethods inherited from class com.expedient.adventofcodejade.BaseSolution
getInput, run
-
Constructor Details
-
SolutionDay16
-
-
Method Details
-
isTraversable
Given a Character, returns true if the character is considered traversable in the maze- Parameters:
c- Character from the maze- Returns:
- whether the Character is traversable
-
getNeighbors
public static List<Pair<Coordinate,Integer>> getNeighbors(Grid<Character> grid, Coordinate current, Direction currentDirection, Set<Pair<Coordinate, Direction>> visited) Given the Grid, current position, current direction, and a Set of previously visited Coordinate, Direction pairs, find neighboring Coordinates and their associated weights (how much traversing to them will impact the score)- Parameters:
grid- Character Grid derived from the inputcurrent- the current locationcurrentDirection- the current directionvisited- Set of visited Coordinate, Direction pairs- Returns:
- a list of Coordinate, Integer pairs representing neighboring vertices and their weights
-
findAllMazeSolutions
public Map<Pair<Coordinate,Direction>, findAllMazeSolutionsList<Pair<Coordinate, Direction>>> (Grid<Character> grid, Coordinate startPoint) Use Dijkstra's Algorithm to find all possible shortest paths through the maze. Uses the weights from the getNeighbors method to account for the fact that turns matter more than steps- Parameters:
grid- Character Grid derived from the puzzle inputstartPoint- Coordinate that we start at- Returns:
- Map containing all Coordinates in the maze, each with a List of Coordinate, Direction pairs that leading to that Coordinate along optimal paths
-
partOne
Find one of the shortest possible paths through the maze with the given parameters, and then calculate its score.- Specified by:
partOnein classBaseSolution- Parameters:
input- the PuzzleInput to be used for the solution- Returns:
- the score of one of the shortest paths through the maze
-
partTwo
Find all shortest paths through the maze, and then figure out how many coordinates (seats) lie along those paths- Specified by:
partTwoin classBaseSolution- Parameters:
input- the PuzzleInput to be used for the solution- Returns:
- the number of seats that lie along the path
-