@@ -17,12 +17,21 @@ public Day17() {
17
17
18
18
public static void main (String [] args ) {
19
19
Day d = new Day17 ();
20
- d .downloadIfNotDownloaded ();
21
- d .downloadExample ();
22
- d .printParts ();
20
+ // System.out.println(d.part2());
21
+ // d.downloadIfNotDownloaded();
22
+ // d.downloadExample();
23
+ // d.printParts();
23
24
// System.in.read();
24
- d .submitPart1 ();
25
+ // d.submitPart1();
25
26
// d.submitPart2();
27
+ long rocks = 1709 ;
28
+ long height = 2642 ;
29
+ while (rocks <1000000000000L ){
30
+ rocks +=1725 ;
31
+ height +=2694 ;
32
+ }
33
+ System .out .println (rocks +", " +height );
34
+ System .out .println ((1561739130578L -187L ));
26
35
}
27
36
28
37
public record Shape (int w , int h , int b , int t , InfiniteGrid g ) {}
@@ -41,8 +50,8 @@ public Object part1() {
41
50
char [] chars = day ().trim ().toCharArray ();
42
51
int i = 0 ;
43
52
int shapeIndex = 0 ;
44
- long heighest = 0 ;
45
- InfiniteGrid s = shapes [shapeIndex ].move (3 , heighest - 4 );
53
+ long highest = 0 ;
54
+ InfiniteGrid s = shapes [shapeIndex ].move (3 , highest - 4 );
46
55
for (int fallenRocks = 0 ; fallenRocks <2022 ; i ++) {
47
56
if (i >=chars .length ) i = 0 ;
48
57
char c = chars [i ];
@@ -66,10 +75,10 @@ public Object part1() {
66
75
// i--;
67
76
g .place (s );
68
77
shapeIndex = (shapeIndex + 1 ) % shapes .length ;
69
- long oldHeighest = heighest ;
70
- heighest = Math .min (s .minY (), heighest );
71
- addWall (g , toIntExact ((oldHeighest - heighest ) + shapes [shapeIndex ].height ()));
72
- s = shapes [shapeIndex ].move (3 , heighest - 3 - shapes [shapeIndex ].height ());
78
+ long oldHeighest = highest ;
79
+ highest = Math .min (s .minY (), highest );
80
+ addWall (g , toIntExact ((oldHeighest - highest ) + shapes [shapeIndex ].height ()));
81
+ s = shapes [shapeIndex ].move (3 , highest - 3 - shapes [shapeIndex ].height ());
73
82
fallenRocks ++;
74
83
}
75
84
@@ -78,7 +87,7 @@ public Object part1() {
78
87
// tog.place(s);
79
88
// System.out.println(tog);
80
89
}
81
- return Math .abs (heighest );
90
+ return Math .abs (highest );
82
91
}
83
92
84
93
private void addWall (InfiniteGrid g , int n ) {
@@ -91,6 +100,64 @@ private void addWall(InfiniteGrid g, int n) {
91
100
92
101
@ Override
93
102
public Object part2 () {
94
- return "" ;
103
+ InfiniteGrid [] shapes = new InfiniteGrid []{
104
+ new InfiniteGrid (new char [][]{"####" .toCharArray ()}),
105
+ new InfiniteGrid (new HashMap <>(Map .of (new Loc (1 , 0 ), '#' , new Loc (0 , 1 ), '#' , new Loc (1 , 1 ), '#' , new Loc (2 , 1 ), '#' , new Loc (1 , 2 ), '#' ))),
106
+ new InfiniteGrid (new HashMap <>(Map .of (new Loc (2 , 0 ), '#' , new Loc (0 , 2 ), '#' , new Loc (1 , 2 ), '#' , new Loc (2 , 2 ), '#' , new Loc (2 , 1 ), '#' ))),
107
+ new InfiniteGrid (new char [][]{{'#' }, {'#' }, {'#' }, {'#' }}),
108
+ new InfiniteGrid (new char [][]{{'#' , '#' }, {'#' , '#' }})
109
+ };
110
+ InfiniteGrid g = new InfiniteGrid (new char [][]{"+-------+" .toCharArray ()});
111
+ addWall (g , 4 );
112
+ char [] chars = day ().trim ().toCharArray ();
113
+ int i = 0 ;
114
+ int shapeIndex = 0 ;
115
+ long highest = 0 ;
116
+ InfiniteGrid s = shapes [shapeIndex ].move (3 , highest - 4 );
117
+ long it = 0 ;
118
+ for (long fallenRocks = 0 ; fallenRocks <1000000000000L ; i ++) {
119
+
120
+ if (i >=chars .length ) i = 0 ;
121
+ if (/*0 == (fallenRocks-1709) % 1725 */ fallenRocks == 5159 -109 || fallenRocks == 3434 -109 ) {
122
+ System .out .println ("i: " +i );
123
+ System .out .println ("shape: " +shapeIndex );
124
+ System .out .println ("highest: " +Math .abs (highest ));
125
+ System .out .println ("fallen: " +fallenRocks );
126
+ }
127
+ char c = chars [i ];
128
+
129
+ if (c == '>' ) {
130
+ InfiniteGrid moved = s .move (1 , 0 );
131
+ if (g .canPlace (moved )) {
132
+ s = moved ;
133
+ }
134
+ } else if (c == '<' ) {
135
+ InfiniteGrid moved = s .move (-1 , 0 );
136
+ if (g .canPlace (moved )) {
137
+ s = moved ;
138
+ }
139
+ }
140
+
141
+ InfiniteGrid moved = s .move (0 , 1 );
142
+ if (g .canPlace (moved )) {
143
+ s = moved ;
144
+ } else {
145
+ // i--;
146
+ g .place (s );
147
+ shapeIndex = (shapeIndex + 1 ) % shapes .length ;
148
+ long oldHeighest = highest ;
149
+ highest = Math .min (s .minY (), highest );
150
+ addWall (g , toIntExact ((oldHeighest - highest ) + shapes [shapeIndex ].height ()));
151
+ s = shapes [shapeIndex ].move (3 , highest - 3 - shapes [shapeIndex ].height ());
152
+ fallenRocks ++;
153
+ }
154
+
155
+ // InfiniteGrid tog = new InfiniteGrid();
156
+ // tog.place(g);
157
+ // tog.place(s);
158
+ // System.out.println(tog);
159
+ it ++;
160
+ }
161
+ return Math .abs (highest );
95
162
}
96
163
}
0 commit comments