Skip to content

Commit a701dc8

Browse files
committed
AOC 2025 day 3
1 parent 58e292b commit a701dc8

File tree

11 files changed

+51
-15
lines changed

11 files changed

+51
-15
lines changed

adventofcode/README.md

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

16631663
| # | Name | Solution | Test |
16641664
|---------:|---------------------------------------------|:------------------------------------:|:---------------------------------:|
16651665
| 20250101 | [Day 1: Secret Entrance][20250101] | ✅[💾][20250101solution] | ✅[💾][20250101tests] |
16661666
| 20250102 | [Day 1: Secret Entrance - Part 2][20250102] | ✅[💾][20250102solution] | ✅[💾][20250102tests] |
16671667
| 20250201 | [Day 2: Gift Shop][20250201] | ✅[💾][20250201solution] | ✅[💾][20250201tests] |
16681668
| 20250202 | [Day 2: Gift Shop - Part 2][20250202] | ✅[💾][20250202solution] | ✅[💾][20250202tests] |
1669-
| 20250301 | [Day 3: ][20250301] | [💾][20250301solution] | [💾][20250301tests] |
1670-
| 20250302 | [Day 3: - Part 2][20250302] | [💾][20250302solution] | [💾][20250302tests] |
1669+
| 20250301 | [Day 3: Lobby ][20250301] | ✅[💾][20250301solution] | ✅[💾][20250301tests] |
1670+
| 20250302 | [Day 3: Lobby - Part 2][20250302] | ✅[💾][20250302solution] | ✅[💾][20250302tests] |
16711671
| 20250401 | [Day 4: ][20250401] | [💾][20250401solution] | [💾][20250401tests] |
16721672
| 20250402 | [Day 4: - Part 2][20250402] | [💾][20250402solution] | [💾][20250402tests] |
16731673
| 20250501 | [Day 5: ][20250501] | [💾][20250501solution] | [💾][20250501tests] |

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

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

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

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

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

31-
private void run(final Scanner in) {
32-
// not yet implemented
29+
private void run(final Scanner in, final int numberOfBatteries) {
30+
long jolts = 0;
31+
32+
while (in.hasNextLine()) {
33+
final String line = in.nextLine();
34+
35+
long currentJolts = 0;
36+
int startIndex = 0;
37+
for (int battery = numberOfBatteries - 1; battery >= 0; --battery) {
38+
int maxValue = 0;
39+
int maxIndex = startIndex;
40+
for (int i = startIndex; i < line.length() - battery; ++i) {
41+
final int value = line.charAt(i) - '0';
42+
43+
if (value > maxValue) {
44+
maxValue = value;
45+
maxIndex = i;
46+
}
47+
}
48+
49+
startIndex = maxIndex + 1;
50+
currentJolts += maxValue * (long) Math.pow(10, battery);
51+
}
52+
53+
jolts += currentJolts;
54+
}
55+
56+
print(jolts);
3357
}
3458
}

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

adventofcode/src/test/resources/org/ck/adventofcode/year2025/day03/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+
357
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
987654321111111
2+
811111111111119
3+
234234234234278
4+
818181911112111
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
172886048065379

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

0 commit comments

Comments
 (0)