Skip to content

Commit

Permalink
Cleaning solution for 2023, Day 14
Browse files Browse the repository at this point in the history
  • Loading branch information
zodac committed Dec 14, 2023
1 parent 87b7770 commit dad8e24
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 274 deletions.
4 changes: 3 additions & 1 deletion 2022/src/main/java/me/zodac/advent/Day12.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import me.zodac.advent.pojo.Point;
import me.zodac.advent.pojo.grid.AdjacentPointsSelector;
import me.zodac.advent.search.BreadthFirstSearcher;
Expand Down Expand Up @@ -92,7 +93,8 @@ public static long findShortestPathFromPossibleStartsToEnd(final List<String> va
long minDistance = Long.MAX_VALUE;
for (final Point startingPoint : startPoints) {
minDistance = Math.min(minDistance, BreadthFirstSearcher.findShortestDistance(startingPoint, endPoints, heightsByPoint,
(point) -> point.getAdjacentPoints(AdjacentPointsSelector.createForUnboundedGrid(false, false))));
(point) -> point.getAdjacentPoints(AdjacentPointsSelector.createForUnboundedGrid(false, false))
.collect(Collectors.toSet())));
}
return minDistance;
}
Expand Down
11 changes: 4 additions & 7 deletions 2023/src/main/java/me/zodac/advent/Day03.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package me.zodac.advent;

import java.util.List;
import java.util.Set;
import me.zodac.advent.pojo.Point;
import me.zodac.advent.pojo.grid.AdjacentPointsSelector;
import me.zodac.advent.pojo.grid.CharacterGrid;
Expand Down Expand Up @@ -72,10 +71,9 @@ private static boolean isNotEnginePart(final char character) {

private static long findSumOfNumbersForPart(final CharacterGrid characterGrid, final Point partPoint) {
final AdjacentPointsSelector adjacentPointsSelector = AdjacentPointsSelector.createForBoundedGrid(false, true, characterGrid.numberOfRows());
final Set<Point> adjacentPoints = partPoint.getAdjacentPoints(adjacentPointsSelector);

return adjacentPoints
.stream()
return partPoint
.getAdjacentPoints(adjacentPointsSelector)
.filter(point -> Character.isDigit(characterGrid.at(point)))
.mapToInt(point -> findNumberInRow(characterGrid, point))
.distinct()
Expand Down Expand Up @@ -139,10 +137,9 @@ private static boolean isNotGear(final char character) {

private static long findSumOfGearRatios(final CharacterGrid characterGrid, final Point gearPoint) {
final AdjacentPointsSelector adjacentPointsSelector = AdjacentPointsSelector.createForBoundedGrid(false, true, characterGrid.numberOfRows());
final Set<Point> adjacentPoints = gearPoint.getAdjacentPoints(adjacentPointsSelector);

final List<Integer> gearRatioValues = adjacentPoints
.stream()
final List<Integer> gearRatioValues = gearPoint
.getAdjacentPoints(adjacentPointsSelector)
.filter(point -> Character.isDigit(characterGrid.at(point)))
.map(point -> findNumberInRow(characterGrid, point))
.distinct()
Expand Down
Loading

0 comments on commit dad8e24

Please sign in to comment.