Skip to content

Commit e1f6a8c

Browse files
committed
chore: add helpers, clean up, prepare
1 parent 5ae3da9 commit e1f6a8c

File tree

16 files changed

+799
-6
lines changed

16 files changed

+799
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
strategy:
6363
fail-fast: false
6464
matrix:
65-
toolchain: [ 1.56.1, stable ]
65+
toolchain: [ 1.70.0, stable ]
6666
os: [ ubuntu ]
6767
ignore-lock: [ false ]
6868
all-features: [ true ]

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
name = "adventofcode2024-clp"
33
version = "0.1.0"
44
edition = "2021"
5-
rust-version = "1.56.1"
5+
rust-version = "1.70.0"
66

77
[features]
88
slow = []
99
utils = []
1010

1111
[dependencies]
12+
itertools = "0.13.0"
13+
num = "0.4.3"
14+
regex = "1.11.1"
15+
strum = { version = "0.26.3", features = ["derive"] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ My solutions to the Advent of Code 2024 puzzles in Rust 🦀
44

55
## Requirements
66

7-
* [Rust](https://www.rust-lang.org/) 1.56.1 or later
7+
* [Rust](https://www.rust-lang.org/) 1.70.0 or later
88

99
## Running the tests
1010

src/day_01.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn part_1() -> usize {
2+
0
3+
}

src/helpers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
1+
pub mod direction;
2+
pub mod looping;
3+
pub mod pt;
4+
pub mod pt_3d;
5+
pub mod regex;

src/helpers/direction.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::ops::Neg;
2+
3+
use num::{one, zero, One, Zero};
4+
use strum::{Display, EnumCount, FromRepr};
5+
6+
use crate::helpers::pt::Pt;
7+
8+
/// ↓ ↑ ← →
9+
#[repr(u8)]
10+
#[derive(
11+
Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, FromRepr, EnumCount, Display,
12+
)]
13+
pub enum Direction {
14+
Right,
15+
Down,
16+
Left,
17+
Up,
18+
}
19+
20+
impl Direction {
21+
/// Turns 90 degrees to the left.
22+
pub fn turn_left(&self) -> Self {
23+
Self::from_repr(((*self as u8) + 3) % (Self::COUNT as u8)).unwrap()
24+
}
25+
26+
/// Turns 90 degrees to the right.
27+
pub fn turn_right(&self) -> Self {
28+
Self::from_repr(((*self as u8) + 1) % (Self::COUNT as u8)).unwrap()
29+
}
30+
31+
/// Turns around (e.g. performs a 180 degrees turn).
32+
pub fn turn_around(&self) -> Self {
33+
Self::from_repr(((*self as u8) + 2) % (Self::COUNT as u8)).unwrap()
34+
}
35+
36+
/// Returns the displacement to apply to move one step in this direction.
37+
/// The displacement is returned as a [`Pt`].
38+
///
39+
/// # Notes
40+
///
41+
/// Because this enum is meant to be used to move around a map represented as a series of rows
42+
/// like on a computer screen, `Up`'s displacement will _subtract_ one from the Y axis, while
43+
/// `Down`'s will _add_ one to the Y axis.
44+
pub fn displacement<T>(&self) -> Pt<T>
45+
where
46+
T: Zero + One + Neg<Output = T>,
47+
{
48+
match self {
49+
Direction::Right => Pt::new(one(), zero()),
50+
Direction::Down => Pt::new(zero(), one()),
51+
Direction::Left => Pt::new(-one::<T>(), zero()),
52+
Direction::Up => Pt::new(zero(), -one::<T>()),
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)