Skip to content

Commit 0781f5e

Browse files
committed
chore: use enum discriminant instead of custom modifier method
1 parent eb79bc4 commit 0781f5e

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

aoclp_solutions/src/y2025/day_01.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,17 @@ fn all_moves() -> impl Iterator<Item = i64> {
4141
}))
4242
}
4343

44+
#[repr(i64)]
4445
#[derive(Debug, Copy, Clone)]
4546
enum RotationDirection {
46-
Left,
47-
Right,
47+
Left = -1,
48+
Right = 1,
4849
}
4950

5051
impl RotationDirection {
5152
fn one_tick(self) -> Rotation {
5253
Rotation { direction: self, clicks: 1 }
5354
}
54-
55-
fn turn_modifier(self) -> i64 {
56-
match self {
57-
RotationDirection::Left => -1,
58-
RotationDirection::Right => 1,
59-
}
60-
}
6155
}
6256

6357
impl FromStr for RotationDirection {
@@ -81,7 +75,7 @@ struct Rotation {
8175

8276
impl Rotation {
8377
fn apply(&self, dial: i64) -> i64 {
84-
(dial + self.clicks * self.direction.turn_modifier()).rem_euclid(100)
78+
(dial + self.clicks * (self.direction as i64)).rem_euclid(100)
8579
}
8680
}
8781

0 commit comments

Comments
 (0)