Skip to content

Commit 94e50f5

Browse files
committed
part 2: bits of pen and paper
1 parent 0aaa18b commit 94e50f5

File tree

1 file changed

+79
-12
lines changed
  • src/main/java/com/sbaars/adventofcode/year22/days

1 file changed

+79
-12
lines changed

src/main/java/com/sbaars/adventofcode/year22/days/Day17.java

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ public Day17() {
1717

1818
public static void main(String[] args) {
1919
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();
2324
// System.in.read();
24-
d.submitPart1();
25+
// d.submitPart1();
2526
// 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));
2635
}
2736

2837
public record Shape(int w, int h, int b, int t, InfiniteGrid g) {}
@@ -41,8 +50,8 @@ public Object part1() {
4150
char[] chars = day().trim().toCharArray();
4251
int i = 0;
4352
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);
4655
for(int fallenRocks = 0; fallenRocks<2022; i++) {
4756
if(i>=chars.length) i = 0;
4857
char c = chars[i];
@@ -66,10 +75,10 @@ public Object part1() {
6675
// i--;
6776
g.place(s);
6877
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());
7382
fallenRocks++;
7483
}
7584

@@ -78,7 +87,7 @@ public Object part1() {
7887
// tog.place(s);
7988
// System.out.println(tog);
8089
}
81-
return Math.abs(heighest);
90+
return Math.abs(highest);
8291
}
8392

8493
private void addWall(InfiniteGrid g, int n) {
@@ -91,6 +100,64 @@ private void addWall(InfiniteGrid g, int n) {
91100

92101
@Override
93102
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);
95162
}
96163
}

0 commit comments

Comments
 (0)