@@ -32,6 +32,7 @@ public static void main(String[] args) {
32
32
Day16 day = new Day16 ();
33
33
day .printParts ();
34
34
new com .sbaars .adventofcode .network .Submit ().submit (day .part1 (), 2015 , 16 , 1 );
35
+ new com .sbaars .adventofcode .network .Submit ().submit (day .part2 (), 2015 , 16 , 2 );
35
36
}
36
37
37
38
private void parseInput () {
@@ -67,14 +68,33 @@ public Object part1() {
67
68
68
69
@ Override
69
70
public Object part2 () {
70
- return 0 ; // Implement in next part
71
+ return aunts .stream ()
72
+ .filter (this ::matchesAllPropertiesWithRanges )
73
+ .mapToInt (aunt -> aunt .number )
74
+ .findFirst ()
75
+ .orElse (0 );
71
76
}
72
77
73
78
private boolean matchesAllProperties (AuntSue aunt ) {
74
79
return aunt .properties .entrySet ().stream ()
75
80
.allMatch (entry -> TARGET_VALUES .get (entry .getKey ()).equals (entry .getValue ()));
76
81
}
77
82
83
+ private boolean matchesAllPropertiesWithRanges (AuntSue aunt ) {
84
+ return aunt .properties .entrySet ().stream ()
85
+ .allMatch (entry -> {
86
+ String property = entry .getKey ();
87
+ int value = entry .getValue ();
88
+ int target = TARGET_VALUES .get (property );
89
+
90
+ return switch (property ) {
91
+ case "cats" , "trees" -> value > target ;
92
+ case "pomeranians" , "goldfish" -> value < target ;
93
+ default -> value == target ;
94
+ };
95
+ });
96
+ }
97
+
78
98
private static class AuntSue {
79
99
private final int number ;
80
100
private final Map <String , Integer > properties ;
0 commit comments