Skip to content

Commit 60d0e38

Browse files
committed
java/2016/10: add solution for part 2
I'm not entirely sure this answer is deterministic, since we are using Hash* collections, although the test continuously passes.
1 parent 2d4e304 commit 60d0e38

File tree

2 files changed

+26
-19
lines changed
  • java/src
    • main/java/com/github/saser/adventofcode/year2016/day10
    • test/java/com/github/saser/adventofcode/year2016/day10

2 files changed

+26
-19
lines changed

java/src/main/java/com/github/saser/adventofcode/year2016/day10/Day10.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,23 @@ private static Result solve(Reader r, int part) {
3131
var bot = visited61.iterator().next();
3232
return Result.ok(Integer.toString(bot));
3333
}
34-
return Result.err("not implemented yet");
34+
var product = 1;
35+
var found = new boolean[3];
36+
for (var entry : paths.entrySet()) {
37+
var list = entry.getValue();
38+
var output = list.get(list.size() - 1);
39+
if (output >= 0 && output <= 2) {
40+
if (found[output]) {
41+
continue;
42+
}
43+
found[output] = true;
44+
product *= entry.getKey();
45+
}
46+
if (found[0] && found[1] && found[2]) {
47+
break;
48+
}
49+
}
50+
return Result.ok(Integer.toString(product));
3551
}
3652

3753
private static class Network {

java/src/test/java/com/github/saser/adventofcode/year2016/day10/Day10Test.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,13 @@ public void part1Actual() throws IOException {
1717
}
1818
}
1919

20-
// @Test
21-
// public void part2Example() {
22-
// var input = new StringReader("");
23-
// var output = "";
24-
// var result = Day10.part2(input);
25-
// Assert.assertEquals("no error", "", result.error);
26-
// Assert.assertEquals("correct output", output, result.answer);
27-
// }
28-
29-
// @Test
30-
// public void part2Actual() throws IOException {
31-
// try (var input = new FileReader("inputs/2016/10")) {
32-
// var output = "";
33-
// var result = Day10.part2(input);
34-
// Assert.assertEquals("no error", "", result.error);
35-
// Assert.assertEquals("correct output", output, result.answer);
36-
// }
37-
// }
20+
@Test
21+
public void part2Actual() throws IOException {
22+
try (var input = new FileReader("inputs/2016/10")) {
23+
var output = "143153";
24+
var result = Day10.part2(input);
25+
Assert.assertEquals("no error", "", result.error);
26+
Assert.assertEquals("correct output", output, result.answer);
27+
}
28+
}
3829
}

0 commit comments

Comments
 (0)