File tree 1 file changed +25
-1
lines changed
src/main/java/com/sbaars/adventofcode/year16/days
1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import com .sbaars .adventofcode .year16 .Day2016 ;
4
4
import java .util .Arrays ;
5
+ import java .util .List ;
6
+ import java .util .stream .Collectors ;
5
7
6
8
public class Day3 extends Day2016 {
7
9
public Day3 () {
@@ -28,6 +30,28 @@ public Object part1() {
28
30
29
31
@ Override
30
32
public Object part2 () {
31
- return "" ;
33
+ List <String > lines = dayStream ().collect (Collectors .toList ());
34
+ int validTriangles = 0 ;
35
+
36
+ for (int i = 0 ; i < lines .size (); i += 3 ) {
37
+ int [][] triangles = new int [3 ][3 ];
38
+
39
+ // Read three rows
40
+ for (int row = 0 ; row < 3 ; row ++) {
41
+ String [] nums = lines .get (i + row ).trim ().split ("\\ s+" );
42
+ for (int col = 0 ; col < 3 ; col ++) {
43
+ triangles [row ][col ] = Integer .parseInt (nums [col ]);
44
+ }
45
+ }
46
+
47
+ // Check each column as a triangle
48
+ for (int col = 0 ; col < 3 ; col ++) {
49
+ if (isValidTriangle (triangles [0 ][col ], triangles [1 ][col ], triangles [2 ][col ])) {
50
+ validTriangles ++;
51
+ }
52
+ }
53
+ }
54
+
55
+ return validTriangles ;
32
56
}
33
57
}
You can’t perform that action at this time.
0 commit comments