@@ -92,9 +92,9 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
92
92
Direction facing = guardStart .b ();
93
93
long x = pos .x , y = pos .y ;
94
94
Set <Loc > visitedPositions = new HashSet <>();
95
- Set <Triple < Long , Long , Direction >> visitedStates = new HashSet <>();
95
+ Set <Pair < Loc , Direction >> visitedStates = new HashSet <>();
96
96
visitedPositions .add (new Loc (x , y ));
97
- visitedStates .add (Triple .of (x , y , facing ));
97
+ visitedStates .add (Pair .of (pos , facing ));
98
98
boolean looped = false ;
99
99
100
100
while (true ) {
@@ -106,7 +106,7 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
106
106
long nSteps = Math .min (stepsToObst , stepsToEdge );
107
107
if (nSteps <= 0 ) {
108
108
facing = facing .turn (true );
109
- Triple < Long , Long , Direction > state = Triple .of (x , y , facing );
109
+ Pair < Loc , Direction > state = Pair .of (pos , facing );
110
110
if (visitedStates .contains (state )) {
111
111
looped = true ;
112
112
break ;
@@ -117,12 +117,11 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
117
117
continue ;
118
118
} else {
119
119
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 ;
124
123
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 );
126
125
if (visitedStates .contains (state )) {
127
126
looped = true ;
128
127
break ;
@@ -138,7 +137,7 @@ private Triple<Integer, Set<Loc>, Boolean> simulate(InfiniteGrid grid, Obstructi
138
137
Loc nextPos = new Loc (nx , ny );
139
138
if (obstructionData .obstruction ().contains (nextPos )) {
140
139
facing = facing .turn (true );
141
- Triple < Long , Long , Direction > state = Triple .of (x , y , facing );
140
+ Pair < Loc , Direction > state = Pair .of (pos , facing );
142
141
if (visitedStates .contains (state )) {
143
142
looped = true ;
144
143
break ;
0 commit comments