Skip to content

Commit 77c163d

Browse files
committed
Year 2025 Day 3
1 parent 03118b5 commit 77c163d

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-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) | 1 |
82+
| 3 | [Lobby](https://adventofcode.com/2025/day/3) | [Source](src/year2025/day03.rs) | 60 |
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! # Lobby
2+
pub fn parse(input: &str) -> Vec<&[u8]> {
3+
input.lines().map(str::as_bytes).collect()
4+
}
5+
6+
pub fn part1(input: &[&[u8]]) -> u64 {
7+
solve(input, 2)
8+
}
9+
10+
pub fn part2(input: &[&[u8]]) -> u64 {
11+
solve(input, 12)
12+
}
13+
14+
fn solve(banks: &[&[u8]], limit: usize) -> u64 {
15+
banks
16+
.iter()
17+
.map(|&bank| {
18+
let mut max = 0;
19+
let mut start = 0;
20+
21+
(0..limit).rev().fold(0, |joltage, digit| {
22+
let end = bank.len() - digit;
23+
24+
(max, start) = (start..end).fold((0, 0), |(max, start), i| {
25+
if bank[i] > max { (bank[i], i + 1) } else { (max, start) }
26+
});
27+
28+
10 * joltage + (max - b'0') as u64
29+
})
30+
})
31+
.sum()
32+
}

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)