44
55import java .util .ArrayList ;
66import java .util .List ;
7+ import java .util .stream .Stream ;
78
89public class CeresSearch {
910
@@ -35,7 +36,7 @@ public CeresSearch(char[][] input){
3536 }
3637
3738 public long solveA () {
38- return xPositions .stream ().map (this ::find ).reduce ( 0 , Integer :: sum );
39+ return xPositions .stream ().mapToInt (this ::find ).sum ( );
3940 }
4041
4142 public long solveB () {
@@ -45,16 +46,10 @@ public long solveB() {
4546 private int find (Vector2 xPos ) {
4647 char [] word = { M , A , S };
4748
48- int totalCount = find (word , 0 , xPos , new Vector2 (-1 ,-1 ));
49- totalCount += find (word , 0 , xPos , new Vector2 (-1 ,1 ));
50- totalCount += find (word , 0 , xPos , new Vector2 (1 ,-1 ));
51- totalCount += find (word , 0 , xPos , new Vector2 (1 ,1 ));
52- totalCount += find (word , 0 , xPos , new Vector2 (-1 ,0 ));
53- totalCount += find (word , 0 , xPos , new Vector2 (1 ,0 ));
54- totalCount += find (word , 0 , xPos , new Vector2 (0 ,-1 ));
55- totalCount += find (word , 0 , xPos , new Vector2 (0 ,1 ));
49+ return Stream .of (Vector2 .down (), Vector2 .up (), Vector2 .right (), Vector2 .left (),
50+ Vector2 .upLeft (), Vector2 .upRight (), Vector2 .downLeft (), Vector2 .downRight ())
51+ .mapToInt (dir -> find (word , 0 , xPos , dir )).sum ();
5652
57- return totalCount ;
5853 }
5954
6055 private int find (final char [] word , int letterIndex , Vector2 position , final Vector2 direction ) {
0 commit comments