Skip to content

Commit bd70b28

Browse files
committed
chore: add 2025 init
Signed-off-by: markkovari <kovarimarkofficial@gmail.com>
1 parent 33f3943 commit bd70b28

4 files changed

Lines changed: 93 additions & 0 deletions

File tree

2025/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

2025/Cargo.lock

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

2025/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "aoc_2025"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

2025/src/main.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use std::str::FromStr;
2+
use std::error::Error;
3+
4+
5+
#[derive(Debug)]
6+
enum Rotation {
7+
Left(i32),
8+
Right(i32),
9+
}
10+
11+
#[derive(Debug)]
12+
struct Dial {
13+
position: i32,
14+
}
15+
16+
impl Default for Dial {
17+
fn default() -> Self {
18+
Dial { position: 50 }
19+
}
20+
}
21+
22+
23+
impl Dial {
24+
pub fn rotate(&mut self, _rotation: Rotation) {
25+
self.position;
26+
}
27+
28+
pub fn isZero(self) -> bool {
29+
self.position == 0
30+
}
31+
}
32+
33+
#[derive(Debug)]
34+
pub enum ParseRotationError {
35+
InvalidDirectionLength,
36+
InvalidDirectionChar,
37+
}
38+
39+
impl FromStr for Rotation {
40+
type Err = ParseRotationError;
41+
42+
// Required method
43+
fn from_str(s: &str) -> Result<Self, Self::Err> {
44+
if s.is_empty() {
45+
return Err(ParseRotationError::InvalidDirectionLength);
46+
}
47+
let (dir_char, rotation_amount) = s.split_at(1);
48+
49+
let rotation: i32 = rotation_amount.parse()?;
50+
match dir_char {
51+
"R" => Rotation { Right: rotation },
52+
"L" => Rotation { Left: rotation },
53+
_ => Err(ParseRotationError::InvalidDirectionChar),
54+
}
55+
}
56+
}
57+
58+
pub fn parse_rotations(input: String) -> Option<Vec<Rotation>> {
59+
input.lines().map(|l| l.parse())
60+
}
61+
62+
fn main() {
63+
let initial_text = r#"L68
64+
L30
65+
R48
66+
L5
67+
R60
68+
L55
69+
L1
70+
L99
71+
R14
72+
L82"#;
73+
74+
if let Ok(rotations) = parse_rotations(initial_text.to_string()) {
75+
println!("{:?}", rotations);
76+
}
77+
78+
println!("Hello, world!");
79+
}

0 commit comments

Comments
 (0)