Skip to content

Commit 822dc75

Browse files
committed
Remove optimization
Not smart
1 parent 8f4999b commit 822dc75

File tree

1 file changed

+6
-15
lines changed
  • src/main/java/com/sbaars/adventofcode2019/days

1 file changed

+6
-15
lines changed

src/main/java/com/sbaars/adventofcode2019/days/Day18.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ public Object part1() throws IOException {
119119
//List<Character> collectedKeys = new ArrayList<>();
120120
//int keysToCollect = findPos('a', 'z').size();
121121
List<Point> keys = findPos('a', 'z');
122-
Map<Route, List<Point>> routes = new HashMap<>();
123-
List<Point> requiredRoutes = new ArrayList<>(keys);
124-
requiredRoutes.add(me);
125-
for(int i = 0; i<requiredRoutes.size(); i++) {
126-
for(int j = i+1; j<requiredRoutes.size(); j++) {
127-
List<Point> r = charGrid.findPath(requiredRoutes.get(i), requiredRoutes.get(j));
128-
//System.out.println(r.size()+", "+new Route(requiredRoutes.get(i), requiredRoutes.get(j)));
129-
routes.put(new Route(requiredRoutes.get(i), requiredRoutes.get(j)), r);
130-
}
131-
}
132122
//List<Point> doors = findPos('A', 'Z');
133123
/*int steps = 0;
134124
//while(collectedKeys.size()<keysToCollect) {
@@ -156,7 +146,7 @@ public Object part1() throws IOException {
156146
System.out.println(steps);
157147
}*/
158148
//System.out.println(Arrays.toString(reachableKeys.toArray()));
159-
return findSteps(me, new TreeSet<>(), keys, routes);
149+
return findSteps(me, new TreeSet<>(), keys);
160150
}
161151

162152
public List<Point> getRoute(Map<Route, List<Point>> routes, Point p1, Point p2){
@@ -177,7 +167,7 @@ public boolean canTakeRoute(List<Point> route, TreeSet<Character> keys) {
177167

178168
//int lowest = Integer.MAX_VALUE;
179169
Map<State, Integer> cachedResult = new HashMap<>();
180-
public int findSteps(Point me, TreeSet<Character> collectedKeys, List<Point> keys, Map<Route, List<Point>> routes) {
170+
public int findSteps(Point me, TreeSet<Character> collectedKeys, List<Point> keys) {
181171
Integer cachedRes = cachedResult.get(new State(me, collectedKeys));
182172
if(cachedRes!=null)
183173
return cachedRes;
@@ -187,8 +177,9 @@ public int findSteps(Point me, TreeSet<Character> collectedKeys, List<Point> key
187177
} else if(currentSteps>=lowest) {
188178
return currentSteps;
189179
}*/
190-
//System.out.println(Arrays.toString(collectedKeys.toArray()));
191-
List<List<Point>> possibleMoves = keys.stream().map(e -> getRoute(routes, me, e)).filter(e -> canTakeRoute(e, collectedKeys)).collect(Collectors.toList());
180+
181+
List<List<Point>> possibleMoves = keys.stream().map(e -> charGrid.findPath(me, e)).filter(e -> !e.isEmpty()).collect(Collectors.toList());
182+
System.out.println(Arrays.toString(collectedKeys.toArray()));
192183
//System.out.println("moves "+possibleMoves.size());
193184
//possibleMoves.addAll(doors.stream().filter(e -> collectedKeys.contains(grid[e.y][e.x])).map(e -> charGrid.findPath(meNow, e)).filter(e -> !e.isEmpty()).collect(Collectors.toList()));
194185
//List<Point> takenMove = possibleMoves.stream().reduce((a, b) -> a.size()<b.size() ? a : b).get();
@@ -210,7 +201,7 @@ public int findSteps(Point me, TreeSet<Character> collectedKeys, List<Point> key
210201
//System.out.println(collected);
211202
//grid[newLoc.y][newLoc.x] = '@';
212203
//System.out.println("Taken move "+collected+" for "+(takenMove.size()-1));
213-
nSteps.add(findSteps(newLoc, myKeys, keyLocs, routes) + takenMove.size()-1);
204+
nSteps.add(findSteps(newLoc, myKeys, keyLocs) + takenMove.size()-1);
214205
}
215206
int res = nSteps.stream().mapToInt(e -> e).min().orElse(0);
216207
cachedResult.put(new State(me, collectedKeys), res);

0 commit comments

Comments
 (0)