Skip to content

Commit a8d1f82

Browse files
committed
2025 day 1
1 parent 482a7b1 commit a8d1f82

File tree

7 files changed

+93
-2
lines changed

7 files changed

+93
-2
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/aoc/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ year2017 = { path = "../year2017", optional = true }
1616
year2018 = { path = "../year2018", optional = true }
1717
year2019 = { path = "../year2019", optional = true }
1818
year2024 = { path = "../year2024", optional = true }
19+
year2025 = { path = "../year2025", optional = true }
1920

2021
[features]
2122
default = ["all-years", "all-simd", "unsafe", "test-runner"]
2223
const_lut = ["year2024?/const_lut"]
2324
all-simd = ["utils/all-simd"]
2425
test-runner = []
2526
# xtask update features
26-
all-years = ["year2015", "year2016", "year2017", "year2018", "year2019", "year2024"]
27-
unsafe = ["year2015?/unsafe", "year2016?/unsafe", "year2017?/unsafe", "year2018?/unsafe", "year2019?/unsafe", "year2024?/unsafe", "utils/unsafe"]
27+
all-years = ["year2015", "year2016", "year2017", "year2018", "year2019", "year2024", "year2025"]
28+
unsafe = ["year2015?/unsafe", "year2016?/unsafe", "year2017?/unsafe", "year2018?/unsafe", "year2019?/unsafe", "year2024?/unsafe", "year2025?/unsafe", "utils/unsafe"]
2829

2930
[lints]
3031
workspace = true

crates/aoc/src/years.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub mod year2019 {
3535
pub mod year2024 {
3636
pub use ::utils::puzzles_noop as puzzles;
3737
}
38+
#[cfg(not(feature = "year2025"))]
39+
pub mod year2025 {
40+
pub use ::utils::puzzles_noop as puzzles;
41+
}
3842
#[cfg(feature = "year2015")]
3943
pub use ::year2015;
4044
#[cfg(feature = "year2016")]
@@ -47,6 +51,8 @@ pub use ::year2018;
4751
pub use ::year2019;
4852
#[cfg(feature = "year2024")]
4953
pub use ::year2024;
54+
#[cfg(feature = "year2025")]
55+
pub use ::year2025;
5056

5157
/// Macro which invokes a callback macro with a list of all implemented puzzle solutions.
5258
///
@@ -119,6 +125,7 @@ macro_rules! all_puzzles {
119125
$crate::year2018::puzzles,
120126
$crate::year2019::puzzles,
121127
$crate::year2024::puzzles,
128+
$crate::year2025::puzzles,
122129

123130
$callback
124131
]

crates/year2025/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "year2025"
3+
authors = { workspace = true }
4+
edition = { workspace = true }
5+
license = { workspace = true }
6+
publish = { workspace = true }
7+
repository = { workspace = true }
8+
rust-version = { workspace = true }
9+
10+
[dependencies]
11+
utils = { path = "../utils", default-features = false }
12+
13+
[features]
14+
unsafe = ["utils/unsafe"]

crates/year2025/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Solutions for [Advent of Code 2025](https://adventofcode.com/2025)

crates/year2025/src/day01.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use utils::prelude::*;
2+
3+
/// Counting how many times a dial passes zero.
4+
#[derive(Clone, Debug)]
5+
pub struct Day01 {
6+
turns: Vec<(Direction, i32)>,
7+
}
8+
9+
parser::parsable_enum! {
10+
#[derive(Clone, Copy, Debug)]
11+
enum Direction {
12+
"L" => Left = -1,
13+
"R" => Right = 1,
14+
}
15+
}
16+
17+
impl Day01 {
18+
pub fn new(input: &str, _: InputType) -> Result<Self, InputError> {
19+
Ok(Self {
20+
turns: Direction::PARSER
21+
.then(parser::number_range(1i32..=999))
22+
.parse_lines(input)?,
23+
})
24+
}
25+
26+
#[must_use]
27+
pub fn part1(&self) -> u32 {
28+
let mut zero_count = 0;
29+
let mut pos = 50;
30+
for &(dir, steps) in &self.turns {
31+
pos = (pos + (steps * dir as i32)).rem_euclid(100);
32+
zero_count += u32::from(pos == 0);
33+
}
34+
zero_count
35+
}
36+
37+
#[must_use]
38+
pub fn part2(&self) -> u32 {
39+
let mut zero_count = 0;
40+
let mut pos = 50;
41+
for &(dir, steps) in &self.turns {
42+
zero_count += match dir {
43+
Direction::Left => ((100 - pos + steps) / 100) as u32 - u32::from(pos == 0),
44+
Direction::Right => ((pos + steps) / 100) as u32,
45+
};
46+
pos = (pos + (steps * dir as i32)).rem_euclid(100);
47+
}
48+
zero_count
49+
}
50+
}
51+
52+
examples!(Day01 -> (u32, u32) [
53+
{input: "L68\nL30\nR48\nL5\nR60\nL55\nL1\nL99\nR14\nL82", part1: 3, part2: 6},
54+
]);

crates/year2025/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![doc = include_str!("../README.md")]
2+
#![cfg_attr(not(feature = "unsafe"), forbid(unsafe_code))]
3+
4+
utils::year!(2025 => year2025, ${
5+
1 => day01::Day01,
6+
});

0 commit comments

Comments
 (0)