Skip to content

Commit 0d88568

Browse files
committed
2025 01.1
1 parent 64ec572 commit 0d88568

File tree

5 files changed

+153
-1
lines changed

5 files changed

+153
-1
lines changed

data

Submodule data updated from 1952faa to 30b3449

src/aoc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ pub mod y2021;
1414
pub mod y2022;
1515
pub mod y2023;
1616
pub mod y2024;
17+
pub mod y2025;

src/aoc/y2025/day00.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2025 Lexi Robinson
2+
//
3+
// Licensed under the EUPL, Version 1.2
4+
//
5+
// You may not use this work except in compliance with the Licence.
6+
// You should have received a copy of the Licence along with this work. If not, see:
7+
// <https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12>.
8+
// See the Licence for the specific language governing permissions and limitations under the Licence.
9+
10+
pub fn part_1(data: crate::DataIn) -> crate::AoCResult<String> {
11+
let ret = data.count();
12+
Ok(ret.to_string())
13+
}
14+
15+
inventory::submit!(crate::AoCDay {
16+
year: "2025",
17+
day: "0",
18+
part_1: crate::AoCPart {
19+
main: part_1,
20+
example: part_1
21+
},
22+
part_2: None
23+
});

src/aoc/y2025/day01.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright (c) 2025 Lexi Robinson
2+
//
3+
// Licensed under the EUPL, Version 1.2
4+
//
5+
// You may not use this work except in compliance with the Licence.
6+
// You should have received a copy of the Licence along with this work. If not, see:
7+
// <https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12>.
8+
// See the Licence for the specific language governing permissions and limitations under the Licence.
9+
10+
use std::fmt::Display;
11+
use std::str::FromStr;
12+
13+
use crate::AoCError;
14+
15+
#[derive(Debug)]
16+
enum Instruction {
17+
Left(i16),
18+
Right(i16),
19+
}
20+
21+
impl FromStr for Instruction {
22+
type Err = AoCError;
23+
24+
fn from_str(s: &str) -> Result<Self, Self::Err> {
25+
let (dir, count) = s
26+
.split_at_checked(1)
27+
.ok_or(AoCError::new("Unexpected utf sequence"))?;
28+
29+
let count = count.parse().map_err(AoCError::new_from_parseerror)?;
30+
31+
Ok(match dir {
32+
"L" => Self::Left(count),
33+
"R" => Self::Right(count),
34+
c => return Err(AoCError::new(format!("Unexpected direction {c}!"))),
35+
})
36+
}
37+
}
38+
39+
impl Display for Instruction {
40+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41+
write!(
42+
f,
43+
"Rotate {} {} clicks",
44+
match self {
45+
Self::Left(_) => "left",
46+
Self::Right(_) => "right",
47+
},
48+
match self {
49+
Self::Left(i) => i,
50+
Self::Right(i) => i,
51+
}
52+
)
53+
}
54+
}
55+
56+
#[derive(Debug)]
57+
struct Dial(i64);
58+
59+
impl Default for Dial {
60+
fn default() -> Self {
61+
Self(50)
62+
}
63+
}
64+
65+
impl Display for Dial {
66+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67+
write!(f, "Dial is at {}", self.0)
68+
}
69+
}
70+
71+
impl Dial {
72+
fn rotate(&mut self, instruction: Instruction) {
73+
match instruction {
74+
Instruction::Left(count) => {
75+
let count: i64 = count.into();
76+
self.0 -= count;
77+
}
78+
Instruction::Right(count) => {
79+
let count: i64 = count.into();
80+
self.0 += count;
81+
}
82+
}
83+
self.clampinate();
84+
}
85+
86+
fn clampinate(&mut self) {
87+
while self.0 < 0 {
88+
self.0 += 100;
89+
}
90+
while self.0 > 99 {
91+
self.0 -= 100;
92+
}
93+
}
94+
}
95+
96+
pub fn part_1(data: crate::DataIn) -> crate::AoCResult<String> {
97+
let mut ret = 0;
98+
let mut dial: Dial = Default::default();
99+
for line in data {
100+
let instruction = line.parse()?;
101+
// println!("{dial}\n{instruction}");
102+
dial.rotate(instruction);
103+
if dial.0 == 0 {
104+
ret += 1;
105+
}
106+
}
107+
// println!("{dial}");
108+
Ok(ret.to_string())
109+
}
110+
111+
inventory::submit!(crate::AoCDay {
112+
year: "2025",
113+
day: "1",
114+
part_1: crate::AoCPart {
115+
main: part_1,
116+
example: part_1
117+
},
118+
part_2: None
119+
});

src/aoc/y2025/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2025 Lexi Robinson
2+
//
3+
// Licensed under the EUPL, Version 1.2
4+
//
5+
// You may not use this work except in compliance with the Licence.
6+
// You should have received a copy of the Licence along with this work. If not, see:
7+
// <https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12>.
8+
// See the Licence for the specific language governing permissions and limitations under the Licence.
9+
pub mod day01;

0 commit comments

Comments
 (0)