8000 more refactoring · AbdulRehman56/AdventOfCode-Java@173fe46 · GitHub
[go: up one dir, main page]

Skip to content

Commit 173fe46

Browse files
committed
more refactoring
1 parent 0d9c465 commit 173fe46

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/main/java/com/sbaars/adventofcode/common/Pair.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public static <A, B> Pair<A, B> pair(A a, B b) {
88
return new Pair<>(a, b);
99
}
1010

11+
public static <A, B> Pair<A, B> of(A a, B b) {
12+
return pair(a, b);
13+
}
14+
1115
public A getLeft() {
1216
return a;
1317
}

src/main/java/com/sbaars/adventofcode/network/FetchInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public FetchInput() {
2929
}
3030

3131
public static void main(String[] args) {
32-
new FetchInput().retrieveDay("5", "2024");
32+
new FetchInput().retrieveDay("7", "2024");
3333
}
3434

3535
private void retrieveDay(String day, String year) {

src/main/java/com/sbaars/adventofcode/year24/days/Day6.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
9292
Direction facing = guardStart.b();
9393
long x = pos.x, y = pos.y;
9494
Set<Loc> visitedPositions = new HashSet<>();
95-
Set<Triple<Long, Long, Direction>> visitedStates = new HashSet<>();
95+
Set<Pair<Loc, Direction>> visitedStates = new HashSet<>();
9696
visitedPositions.add(new Loc(x, y));
97-
visitedStates.add(Triple.of(x, y, facing));
97+
visitedStates.add(Pair.of(pos, facing));
9898
boolean looped = false;
9999

100100
while (true) {
@@ -106,7 +106,7 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
106106
long nSteps = Math.min(stepsToObst, stepsToEdge);
107107
if (nSteps <= 0) {
108108
facing = facing.turn(true);
109-
Triple<Long, Long, Direction> state = Triple.of(x, y, facing);
109+
Pair<Loc, Direction> state = Pair.of(pos, facing);
110110
if (visitedStates.contains(state)) {
111111
looped = true;
112112
break;
@@ -117,12 +117,11 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
117117
continue;
118118
} else {
119119
for (long i = 0; i < nSteps; i++) {
120-
Loc l = new Loc(x, y).move(facing);
121-
pos = l;
122-
x = l.x;
123-
y = l.y;
120+
pos = pos.move(facing);
121+
x = pos.x;
122+
y = pos.y;
124123
Loc newPos = new Loc(x, y);
125-
Triple<Long, Long, Direction> state = Triple.of(x, y, facing);
124+
Pair<Loc, Direction> state = Pair.of(pos, facing);
126125
if (visitedStates.contains(state)) {
127126
looped = true;
128127
break;
@@ -138,7 +137,7 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
138137
Loc nextPos = new Loc(nx, ny);
139138
if (obstructionData.obstruction().contains(nextPos)) {
140139
facing = facing.turn(true);
141-
Triple<Long, Long, Direction> state = Triple.of(x, y, facing);
140+
Pair<Loc, Direction> state = Pair.of(pos, facing);
142141
if (visitedStates.contains(state)) {
143142
looped = true;
144143
break;

0 commit comments

Comments
 (0)
0