Skip to content

Commit b843e39

Browse files
committed
Year 2025 Day 1
1 parent eb38d0b commit b843e39

File tree

7 files changed

+88
-1
lines changed

7 files changed

+88
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Advent of Code [![checks-badge]][checks-link] [![docs-badge]][docs-link]
22

3-
Blazing fast Rust solutions for every [Advent of Code] puzzle from 2015 to 2024, taking
3+
*2025 in progress!* Blazing fast Rust solutions for every [Advent of Code] puzzle from 2015 to 2024, taking
44
**470 milliseconds** to solve all 500 stars. Each solution is carefully optimized for performance
55
while ensuring the code remains concise, readable, and idiomatic.
66

@@ -65,10 +65,20 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
6565

6666
![pie-all]
6767

68+
| Year | [2025](#2025) |
69+
| --- | --- |
70+
| Benchmark (ms) | WIP |
71+
6872
| Year | [2015](#2015) | [2016](#2016) | [2017](#2017) | [2018](#2018) | [2019](#2019) | [2020](#2020) | [2021](#2021) | [2022](#2022) | [2023](#2023) | [2024](#2024) |
6973
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
7074
| Benchmark (ms) | 14 | 109 | 57 | 35 | 13 | 220 | 8 | 5 | 5 | 4 |
7175

76+
## 2025
77+
78+
| Day | Problem | Solution | Benchmark (μs) |
79+
| --- | --- | --- | --: |
80+
| 1 | [Secret Entrance](https://adventofcode.com/2025/day/1) | [Source](src/year2025/day01.rs) | 47 |
81+
7282
## 2024
7383

7484
![pie-2024]

benches/benchmark.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ benchmark!(year2024
9393
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12, day13,
9494
day14, day15, day16, day17, day18, day19, day20, day21, day22, day23, day24, day25
9595
);
96+
97+
benchmark!(year2025
98+
day01
99+
);

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ library!(year2024 "Locate the Chief Historian in time for the big Christmas slei
7272
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12, day13,
7373
day14, day15, day16, day17, day18, day19, day20, day21, day22, day23, day24, day25
7474
);
75+
76+
library!(year2025 "???"
77+
day01
78+
);

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn main() {
2727
year2022(),
2828
year2023(),
2929
year2024(),
30+
year2025(),
3031
];
3132

3233
// Run selected solutions.
@@ -138,3 +139,7 @@ run!(year2024
138139
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12, day13,
139140
day14, day15, day16, day17, day18, day19, day20, day21, day22, day23, day24, day25
140141
);
142+
143+
run!(year2025
144+
day01
145+
);

src/year2025/day01.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::util::parse::*;
2+
3+
pub fn parse(input: &str) -> Vec<i32> {
4+
let direction = input.bytes().filter(|&b| b.is_ascii_uppercase());
5+
let amount = input.iter_signed::<i32>();
6+
direction.zip(amount).map(|(d, a)| if d == b'R' { a } else { -a }).collect()
7+
}
8+
9+
pub fn part1(input: &[i32]) -> i32 {
10+
let mut dial: i32 = 50;
11+
let mut password = 0;
12+
13+
for &delta in input {
14+
dial += delta;
15+
password += i32::from(dial % 100 == 0);
16+
}
17+
18+
password
19+
}
20+
21+
pub fn part2(input: &[i32]) -> i32 {
22+
let mut dial: i32 = 50;
23+
let mut password = 0;
24+
25+
for &delta in input {
26+
if delta >= 0 {
27+
password += (dial + delta) / 100;
28+
} else {
29+
password += (100 - dial - delta) / 100 - (100 - dial) / 100;
30+
}
31+
dial = (dial + delta).rem_euclid(100);
32+
}
33+
34+
password
35+
}

tests/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ test!(year2024
8585
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12, day13,
8686
day14, day15, day16, day17, day18, day19, day20, day21, day22, day23, day24, day25
8787
);
88+
89+
test!(year2025
90+
day01
91+
);

tests/year2025/day01.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use aoc::year2025::day01::*;
2+
3+
const EXAMPLE: &str = "\
4+
L68
5+
L30
6+
R48
7+
L5
8+
R60
9+
L55
10+
L1
11+
L99
12+
R14
13+
L82";
14+
15+
#[test]
16+
fn part1_test() {
17+
let input = parse(EXAMPLE);
18+
assert_eq!(part1(&input), 3);
19+
}
20+
21+
#[test]
22+
fn part2_test() {
23+
let input = parse(EXAMPLE);
24+
assert_eq!(part2(&input), 6);
25+
}

0 commit comments

Comments
 (0)