File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
src/main/java/com/sbaars/adventofcode/year15/days Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public static void main(String[] args) {
20
20
Day14 day = new Day14 ();
21
21
day .printParts ();
22
22
new com .sbaars .adventofcode .network .Submit ().submit (day .part1 (), 2015 , 14 , 1 );
23
+ new com .sbaars .adventofcode .network .Submit ().submit (day .part2 (), 2015 , 14 , 2 );
23
24
}
24
25
25
26
private void parseInput () {
@@ -46,7 +47,27 @@ public Object part1() {
46
47
47
48
@ Override
48
49
public Object part2 () {
49
- return 0 ; // Implement in next part
50
+ Map <Reindeer , Integer > points = reindeers .stream ()
51
+ .collect (Collectors .toMap (r -> r , r -> 0 ));
52
+
53
+ // For each second
54
+ for (int second = 1 ; second <= RACE_DURATION ; second ++) {
55
+ final int currentSecond = second ;
56
+ int maxDistance = reindeers .stream ()
57
+ .mapToInt (r -> r .getDistanceAfter (currentSecond ))
58
+ .max ()
59
+ .orElse (0 );
60
+
61
+ // Award points to all reindeers in the lead
62
+ reindeers .stream ()
63
+ .filter (r -> r .getDistanceAfter (currentSecond ) == maxDistance )
64
+ .forEach (r -> points .merge (r , 1 , Integer ::sum ));
65
+ }
66
+
67
+ return points .values ().stream ()
68
+ .mapToInt (Integer ::intValue )
69
+ .max ()
70
+ .orElse (0 );
50
71
}
51
72
52
73
private static class Reindeer {
You can’t perform that action at this time.
0 commit comments