Skip to content

Commit 46a9575

Browse files
committed
AOC 2025 day 1
1 parent 954a285 commit 46a9575

13 files changed

Lines changed: 110 additions & 49 deletions

File tree

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 (0/24)
1661+
# 2025 (2/24)
16621662

1663-
| # | Name | Solution | Test |
1664-
|---------:|-------------------------------|:------------------------------------:|:---------------------------------:|
1665-
| 20250101 | [Day 1: ][20250101] | [💾][20250101solution] | [💾][20250101tests] |
1666-
| 20250102 | [Day 1: - Part 2][20250102] | [💾][20250102solution] | [💾][20250102tests] |
1667-
| 20250201 | [Day 2: ][20250201] | [💾][20250201solution] | [💾][20250201tests] |
1668-
| 20250202 | [Day 2: - Part 2][20250202] | [💾][20250202solution] | [💾][20250202tests] |
1669-
| 20250301 | [Day 3: ][20250301] | [💾][20250301solution] | [💾][20250301tests] |
1670-
| 20250302 | [Day 3: - 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: ][20250201] | [💾][20250201solution] | [💾][20250201tests] |
1668+
| 20250202 | [Day 2: - Part 2][20250202] | [💾][20250202solution] | [💾][20250202tests] |
1669+
| 20250301 | [Day 3: ][20250301] | [💾][20250301solution] | [💾][20250301tests] |
1670+
| 20250302 | [Day 3: - 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] |
16891689

16901690
[20250101]: https://adventofcode.com/2025/day/1
16911691
[20250102]: https://adventofcode.com/2025/day/1#part2
Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,71 @@
11
package org.ck.adventofcode.year2025;
22

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

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

2121
@Override
2222
protected void runPartOne(final Scanner in) {
23-
run(in);
23+
run(
24+
in,
25+
Gatherer.ofSequential(
26+
() -> new AtomicInteger(50),
27+
(state, rotation, downstream) -> {
28+
int current = state.get() + rotation;
29+
30+
state.set(((100 * (1 + Math.abs(current) / 100)) + current) % 100);
31+
if (state.get() == 0) {
32+
downstream.push(1);
33+
}
34+
35+
return !downstream.isRejecting();
36+
}));
2437
}
2538

2639
@Override
2740
protected void runPartTwo(final Scanner in) {
28-
run(in);
41+
run(
42+
in,
43+
Gatherer.ofSequential(
44+
() -> new AtomicInteger(50),
45+
(state, rotation, downstream) -> {
46+
final int current = state.get() + rotation;
47+
48+
final int zeroHits =
49+
(Math.abs(current) / 100)
50+
+ (current == 0 || current < 0 && state.get() > 0 ? 1 : 0);
51+
downstream.push(zeroHits);
52+
53+
state.set(((100 * (1 + Math.abs(current) / 100)) + current) % 100);
54+
return !downstream.isRejecting();
55+
}));
2956
}
3057

31-
private void run(final Scanner in) {
32-
// not yet implemented
58+
private void run(final Scanner in, Gatherer<Integer, AtomicInteger, Integer> gatherer) {
59+
final List<String> lines = new ArrayList<>();
60+
while (in.hasNextLine()) {
61+
lines.add(in.nextLine());
62+
}
63+
64+
print(
65+
lines.stream()
66+
.map(line -> (line.charAt(0) == 'R' ? 1 : -1) * Integer.parseInt(line.substring(1)))
67+
.gather(gatherer)
68+
.mapToInt(Integer::intValue)
69+
.sum());
3370
}
3471
}

adventofcode/src/test/java/org/ck/adventofcode/year2025/Day01Test.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 Day01Test extends BaseAOCTest {
108
@ParameterizedTest
119
@ValueSource(strings = {"01a"})
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
3 4
2-
4 3
3-
2 5
4-
1 3
5-
3 9
1+
3 4
2+
4 3
3+
2 5
4+
1 3
5+
3 9
66
3 3
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
3 4
2-
4 3
3-
2 5
4-
1 3
5-
3 9
1+
3 4
2+
4 3
3+
2 5
4+
1 3
5+
3 9
66
3 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1120

adventofcode/src/test/resources/org/ck/adventofcode/year2025/day01/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+
3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
L68
2+
L30
3+
R48
4+
L5
5+
R60
6+
L55
7+
L1
8+
L99
9+
R14
10+
L82
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6554

0 commit comments

Comments
 (0)