Skip to content

Commit c00e349

Browse files
committed
AOC 2025 day 7
1 parent eb53b32 commit c00e349

File tree

11 files changed

+86
-15
lines changed

11 files changed

+86
-15
lines changed

adventofcode/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@
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 (12/24)
1661+
# 2025 (14/24)
16621662

16631663
| # | Name | Solution | Test |
16641664
|---------:|-------------------------------------------------|:------------------------------------:|:---------------------------------:|
@@ -1674,8 +1674,8 @@
16741674
| 20250502 | [Day 5: Cafeteria - Part 2][20250502] | ✅[💾][20250502solution] | ✅[💾][20250502tests] |
16751675
| 20250601 | [Day 6: Trash Compactor][20250601] | ✅[💾][20250601solution] | ✅[💾][20250601tests] |
16761676
| 20250602 | [Day 6: Trash Compactor - Part 2][20250602] | ✅[💾][20250602solution] | ✅[💾][20250602tests] |
1677-
| 20250701 | [Day 7: ][20250701] | [💾][20250701solution] | [💾][20250701tests] |
1678-
| 20250702 | [Day 7: - Part 2][20250702] | [💾][20250702solution] | [💾][20250702tests] |
1677+
| 20250701 | [Day 7: Laboratories ][20250701] | ✅[💾][20250701solution] | ✅[💾][20250701tests] |
1678+
| 20250702 | [Day 7: Laboratories - Part 2][20250702] | ✅[💾][20250702solution] | ✅[💾][20250702tests] |
16791679
| 20250801 | [Day 8: ][20250801] | [💾][20250801solution] | [💾][20250801tests] |
16801680
| 20250802 | [Day 8: - Part 2][20250802] | [💾][20250802solution] | [💾][20250802tests] |
16811681
| 20250901 | [Day 9: ][20250901] | [💾][20250901solution] | [💾][20250901tests] |
Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,69 @@
11
package org.ck.adventofcode.year2025;
22

33
import java.util.*;
4+
import java.util.concurrent.atomic.AtomicInteger;
5+
import java.util.function.ToLongBiFunction;
46
import org.ck.adventofcode.util.AOCSolution;
57
import org.ck.codechallengelib.annotation.Solution;
68

79
@Solution(
810
id = 20250701,
9-
name = "Day 7: ",
11+
name = "Day 7: Laboratories ",
1012
url = "https://adventofcode.com/2025/day/7",
11-
category = "2025",
12-
solved = false)
13+
category = "2025")
1314
@Solution(
1415
id = 20250702,
15-
name = "Day 7: - Part 2",
16+
name = "Day 7: Laboratories - Part 2",
1617
url = "https://adventofcode.com/2025/day/7#part2",
17-
category = "2025",
18-
solved = false)
18+
category = "2025")
1919
public class Day07 extends AOCSolution {
2020

2121
@Override
2222
protected void runPartOne(final Scanner in) {
23-
run(in);
23+
run(in, (count, _) -> count.get());
2424
}
2525

2626
@Override
2727
protected void runPartTwo(final Scanner in) {
28-
run(in);
28+
run(in, (_, paths) -> Arrays.stream(paths).sum());
2929
}
3030

31-
private void run(final Scanner in) {
32-
// not yet implemented
31+
private void run(final Scanner in, final ToLongBiFunction<AtomicInteger, long[]> resultGetter) {
32+
final List<String> lines = new ArrayList<>();
33+
long[] paths = null;
34+
35+
while (in.hasNextLine()) {
36+
final String line = in.nextLine();
37+
38+
final int start = line.indexOf('S');
39+
if (start > 0) {
40+
paths = new long[line.length()];
41+
paths[start] = 1;
42+
}
43+
44+
lines.add(line);
45+
}
46+
47+
if (paths == null) {
48+
throw new RuntimeException("No strat found");
49+
}
50+
51+
final AtomicInteger splits = new AtomicInteger(0);
52+
for (String line : lines) {
53+
for (int column = 0; column < line.length(); ++column) {
54+
if (line.charAt(column) == '^') {
55+
if (paths[column] > 0) {
56+
paths[column - 1] += paths[column];
57+
paths[column + 1] += paths[column];
58+
59+
paths[column] = 0;
60+
61+
splits.incrementAndGet();
62+
}
63+
}
64+
}
65+
}
66+
67+
print(resultGetter.applyAsLong(splits, paths));
3368
}
3469
}

adventofcode/src/test/java/org/ck/adventofcode/year2025/Day07Test.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 Day07Test 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+
1507

adventofcode/src/test/resources/org/ck/adventofcode/year2025/day07/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+
21
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.......S.......
2+
...............
3+
.......^.......
4+
...............
5+
......^.^......
6+
...............
7+
.....^.^.^.....
8+
...............
9+
....^.^...^....
10+
...............
11+
...^.^...^.^...
12+
...............
13+
..^...^.....^..
14+
...............
15+
.^.^.^.^.^...^.
16+
...............
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1537373473728

adventofcode/src/test/resources/org/ck/adventofcode/year2025/day07/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+
40

0 commit comments

Comments
 (0)