Skip to content

Commit 71df92b

Browse files
committed
Year 2025 Day 3
1 parent 90d489c commit 71df92b

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
7979
| --- | --- | --- | --: |
8080
| 1 | [Secret Entrance](https://adventofcode.com/2025/day/1) | [Source](src/year2025/day01.rs) | 25 |
8181
| 2 | [Gift Shop](https://adventofcode.com/2025/day/2) | [Source](src/year2025/day02.rs) | 2 |
82+
| 3 | [Lobby](https://adventofcode.com/2025/day/3) | [Source](src/year2025/day03.rs) | 611 |
8283

8384
## 2024
8485

benches/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ benchmark!(year2024
9595
);
9696

9797
benchmark!(year2025
98-
day01, day02
98+
day01, day02, day03
9999
);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ library!(year2024 "Locate the Chief Historian in time for the big Christmas slei
7474
);
7575

7676
library!(year2025 "Finish the North Pole decorations in time for Christmas."
77-
day01, day02
77+
day01, day02, day03
7878
);

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ run!(year2024
141141
);
142142

143143
run!(year2025
144-
day01, day02
144+
day01, day02, day03
145145
);

src/year2025/day03.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
pub fn parse(input: &str) -> Vec<&str> {
2+
input.lines().collect()
3+
}
4+
5+
pub fn part1(input: &[&str]) -> u64 {
6+
solve(input, 2)
7+
}
8+
9+
pub fn part2(input: &[&str]) -> u64 {
10+
solve(input, 12)
11+
}
12+
13+
fn solve(lines: &[&str], limit: usize) -> u64 {
14+
let mut bank = [0; 101];
15+
let mut result = 0;
16+
17+
for line in lines {
18+
for (i, b) in line.bytes().enumerate() {
19+
bank[i] = (b - b'0') as u64;
20+
}
21+
22+
let mut row = [0; 101];
23+
24+
for exp in 0..limit {
25+
let tens = 10_u64.pow(exp as u32);
26+
let mut next = [0; 101];
27+
28+
for i in ((limit - exp - 1)..(line.len() - exp)).rev() {
29+
next[i] = (tens * bank[i] + row[i + 1]).max(next[i + 1]);
30+
}
31+
32+
row = next;
33+
}
34+
35+
result += row[0];
36+
}
37+
38+
result
39+
}

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ test!(year2024
8787
);
8888

8989
test!(year2025
90-
day01, day02
90+
day01, day02, day03
9191
);

tests/year2025/day03.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use aoc::year2025::day03::*;
2+
3+
const EXAMPLE: &str = "\
4+
987654321111111
5+
811111111111119
6+
234234234234278
7+
818181911112111";
8+
9+
#[test]
10+
fn part1_test() {
11+
let input = parse(EXAMPLE);
12+
assert_eq!(part1(&input), 357);
13+
}
14+
15+
#[test]
16+
fn part2_test() {
17+
let input = parse(EXAMPLE);
18+
assert_eq!(part2(&input), 3121910778619);
19+
}

0 commit comments

Comments
 (0)