Skip to content

Commit 9532e1e

Browse files
committed
AOC 2025 day 4
1 parent a701dc8 commit 9532e1e

File tree

11 files changed

+107
-39
lines changed

11 files changed

+107
-39
lines changed

adventofcode/README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,34 +1658,34 @@
16581658
[20242402tests]: src/test/java/org/ck/adventofcode/year2024/Day24Test.java
16591659
[20242501tests]: src/test/java/org/ck/adventofcode/year2024/Day25Test.java
16601660

1661-
# 2025 (6/24)
1661+
# 2025 (8/24)
16621662

1663-
| # | Name | Solution | Test |
1664-
|---------:|---------------------------------------------|:------------------------------------:|:---------------------------------:|
1665-
| 20250101 | [Day 1: Secret Entrance][20250101] | ✅[💾][20250101solution] | ✅[💾][20250101tests] |
1666-
| 20250102 | [Day 1: Secret Entrance - Part 2][20250102] | ✅[💾][20250102solution] | ✅[💾][20250102tests] |
1667-
| 20250201 | [Day 2: Gift Shop][20250201] | ✅[💾][20250201solution] | ✅[💾][20250201tests] |
1668-
| 20250202 | [Day 2: Gift Shop - Part 2][20250202] | ✅[💾][20250202solution] | ✅[💾][20250202tests] |
1669-
| 20250301 | [Day 3: Lobby ][20250301] | ✅[💾][20250301solution] | ✅[💾][20250301tests] |
1670-
| 20250302 | [Day 3: Lobby - Part 2][20250302] | ✅[💾][20250302solution] | ✅[💾][20250302tests] |
1671-
| 20250401 | [Day 4: ][20250401] | [💾][20250401solution] | [💾][20250401tests] |
1672-
| 20250402 | [Day 4: - Part 2][20250402] | [💾][20250402solution] | [💾][20250402tests] |
1673-
| 20250501 | [Day 5: ][20250501] | [💾][20250501solution] | [💾][20250501tests] |
1674-
| 20250502 | [Day 5: - Part 2][20250502] | [💾][20250502solution] | [💾][20250502tests] |
1675-
| 20250601 | [Day 6: ][20250601] | [💾][20250601solution] | [💾][20250601tests] |
1676-
| 20250602 | [Day 6: - Part 2][20250602] | [💾][20250602solution] | [💾][20250602tests] |
1677-
| 20250701 | [Day 7: ][20250701] | [💾][20250701solution] | [💾][20250701tests] |
1678-
| 20250702 | [Day 7: - Part 2][20250702] | [💾][20250702solution] | [💾][20250702tests] |
1679-
| 20250801 | [Day 8: ][20250801] | [💾][20250801solution] | [💾][20250801tests] |
1680-
| 20250802 | [Day 8: - Part 2][20250802] | [💾][20250802solution] | [💾][20250802tests] |
1681-
| 20250901 | [Day 9: ][20250901] | [💾][20250901solution] | [💾][20250901tests] |
1682-
| 20250902 | [Day 9: - Part 2][20250902] | [💾][20250902solution] | [💾][20250902tests] |
1683-
| 20251001 | [Day 10: ][20251001] | [💾][20251001solution] | [💾][20251001tests] |
1684-
| 20251002 | [Day 10: - Part 2][20251002] | [💾][20251002solution] | [💾][20251002tests] |
1685-
| 20251101 | [Day 11: ][20251101] | [💾][20251101solution] | [💾][20251101tests] |
1686-
| 20251102 | [Day 11: - Part 2][20251102] | [💾][20251102solution] | [💾][20251102tests] |
1687-
| 20251201 | [Day 12: ][20251201] | [💾][20251201solution] | [💾][20251201tests] |
1688-
| 20251202 | [Day 12: - Part 2][20251202] | [💾][20251202solution] | [💾][20251202tests] |
1663+
| # | Name | Solution | Test |
1664+
|---------:|-------------------------------------------------|:------------------------------------:|:---------------------------------:|
1665+
| 20250101 | [Day 1: Secret Entrance][20250101] | ✅[💾][20250101solution] | ✅[💾][20250101tests] |
1666+
| 20250102 | [Day 1: Secret Entrance - Part 2][20250102] | ✅[💾][20250102solution] | ✅[💾][20250102tests] |
1667+
| 20250201 | [Day 2: Gift Shop][20250201] | ✅[💾][20250201solution] | ✅[💾][20250201tests] |
1668+
| 20250202 | [Day 2: Gift Shop - Part 2][20250202] | ✅[💾][20250202solution] | ✅[💾][20250202tests] |
1669+
| 20250301 | [Day 3: Lobby ][20250301] | ✅[💾][20250301solution] | ✅[💾][20250301tests] |
1670+
| 20250302 | [Day 3: Lobby - Part 2][20250302] | ✅[💾][20250302solution] | ✅[💾][20250302tests] |
1671+
| 20250401 | [Day 4: Printing Department][20250401] | ✅[💾][20250401solution] | ✅[💾][20250401tests] |
1672+
| 20250402 | [Day 4: Printing Department - Part 2][20250402] | ✅[💾][20250402solution] | ✅[💾][20250402tests] |
1673+
| 20250501 | [Day 5: ][20250501] | [💾][20250501solution] | [💾][20250501tests] |
1674+
| 20250502 | [Day 5: - Part 2][20250502] | [💾][20250502solution] | [💾][20250502tests] |
1675+
| 20250601 | [Day 6: ][20250601] | [💾][20250601solution] | [💾][20250601tests] |
1676+
| 20250602 | [Day 6: - Part 2][20250602] | [💾][20250602solution] | [💾][20250602tests] |
1677+
| 20250701 | [Day 7: ][20250701] | [💾][20250701solution] | [💾][20250701tests] |
1678+
| 20250702 | [Day 7: - Part 2][20250702] | [💾][20250702solution] | [💾][20250702tests] |
1679+
| 20250801 | [Day 8: ][20250801] | [💾][20250801solution] | [💾][20250801tests] |
1680+
| 20250802 | [Day 8: - Part 2][20250802] | [💾][20250802solution] | [💾][20250802tests] |
1681+
| 20250901 | [Day 9: ][20250901] | [💾][20250901solution] | [💾][20250901tests] |
1682+
| 20250902 | [Day 9: - Part 2][20250902] | [💾][20250902solution] | [💾][20250902tests] |
1683+
| 20251001 | [Day 10: ][20251001] | [💾][20251001solution] | [💾][20251001tests] |
1684+
| 20251002 | [Day 10: - Part 2][20251002] | [💾][20251002solution] | [💾][20251002tests] |
1685+
| 20251101 | [Day 11: ][20251101] | [💾][20251101solution] | [💾][20251101tests] |
1686+
| 20251102 | [Day 11: - Part 2][20251102] | [💾][20251102solution] | [💾][20251102tests] |
1687+
| 20251201 | [Day 12: ][20251201] | [💾][20251201solution] | [💾][20251201tests] |
1688+
| 20251202 | [Day 12: - Part 2][20251202] | [💾][20251202solution] | [💾][20251202tests] |
16891689

16901690
[20250101]: https://adventofcode.com/2025/day/1
16911691
[20250102]: https://adventofcode.com/2025/day/1#part2

adventofcode/src/main/java/org/ck/adventofcode/year2025/Day04.java

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,73 @@
66

77
@Solution(
88
id = 20250401,
9-
name = "Day 4: ",
9+
name = "Day 4: Printing Department",
1010
url = "https://adventofcode.com/2025/day/4",
11-
category = "2025",
12-
solved = false)
11+
category = "2025")
1312
@Solution(
1413
id = 20250402,
15-
name = "Day 4: - Part 2",
14+
name = "Day 4: Printing Department - Part 2",
1615
url = "https://adventofcode.com/2025/day/4#part2",
17-
category = "2025",
18-
solved = false)
16+
category = "2025")
1917
public class Day04 extends AOCSolution {
2018

2119
@Override
2220
protected void runPartOne(final Scanner in) {
23-
run(in);
21+
run(in, false);
2422
}
2523

2624
@Override
2725
protected void runPartTwo(final Scanner in) {
28-
run(in);
26+
run(in, true);
2927
}
3028

31-
private void run(final Scanner in) {
32-
// not yet implemented
29+
private void run(final Scanner in, final boolean loop) {
30+
final List<String> rows = new ArrayList<>();
31+
32+
while (in.hasNextLine()) {
33+
rows.add(in.nextLine());
34+
}
35+
36+
char[][] grid = new char[rows.size()][rows.get(0).length()];
37+
for (int i = 0; i < rows.size(); ++i) {
38+
for (int j = 0; j < rows.get(i).length(); ++j) {
39+
grid[i][j] = rows.get(i).charAt(j);
40+
}
41+
}
42+
43+
int movable = 0;
44+
boolean moved = false;
45+
do {
46+
char[][] newGrid = new char[grid.length][grid[0].length];
47+
moved = false;
48+
49+
for (int row = 0; row < grid.length; ++row) {
50+
for (int column = 0; column < grid[row].length; ++column) {
51+
int surrounding = 0;
52+
53+
for (int i = Math.max(row - 1, 0); i <= Math.min(row + 1, grid.length - 1); ++i) {
54+
for (int j = Math.max(column - 1, 0);
55+
j <= Math.min(column + 1, grid[i].length - 1);
56+
++j) {
57+
if (i != row || j != column) {
58+
surrounding += grid[i][j] == '@' ? 1 : 0;
59+
}
60+
}
61+
}
62+
63+
if (grid[row][column] == '@' && surrounding < 4) {
64+
moved = true;
65+
++movable;
66+
newGrid[row][column] = '.';
67+
} else {
68+
newGrid[row][column] = grid[row][column];
69+
}
70+
}
71+
}
72+
73+
grid = newGrid;
74+
} while (loop && moved);
75+
76+
print(movable);
3377
}
3478
}

adventofcode/src/test/java/org/ck/adventofcode/year2025/Day04Test.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package org.ck.adventofcode.year2025;
22

33
import org.ck.adventofcode.util.BaseAOCTest;
4-
import org.junit.jupiter.api.Disabled;
54
import org.junit.jupiter.params.ParameterizedTest;
65
import org.junit.jupiter.params.provider.ValueSource;
76

8-
@Disabled
97
class Day04Test extends BaseAOCTest {
108
@ParameterizedTest
119
@ValueSource(strings = {"01a"})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1395

adventofcode/src/test/resources/org/ck/adventofcode/year2025/day04/01.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
13
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
..@@.@@@@.
2+
@@@.@.@.@@
3+
@@@@@.@.@@
4+
@.@@@@..@.
5+
@@.@@@@.@@
6+
.@@@@@@@.@
7+
.@.@.@.@@@
8+
@.@@@.@@@@
9+
.@@@@@@@@.
10+
@.@.@@@.@.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8451

adventofcode/src/test/resources/org/ck/adventofcode/year2025/day04/02.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
43

0 commit comments

Comments
 (0)