diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..ba5fddf --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +lint = "clippy -- -D warnings" diff --git a/src/main.rs b/src/main.rs index d75a590..4d0295a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ fn run_ydp(ydp: YDP, input: Option) { fn main() { let args = std::env::args().skip(1).collect::>(); - let command = args.get(0); + let command = args.first(); match command { Some(command) => match command.as_str() { diff --git a/utils/src/grid.rs b/utils/src/grid.rs index c7bb748..b5a5e8b 100644 --- a/utils/src/grid.rs +++ b/utils/src/grid.rs @@ -706,13 +706,13 @@ pub mod cursors { } } - impl<'a, T, D: Movement> PartialEq for GridCursor<'a, T, D> { + impl PartialEq for GridCursor<'_, T, D> { fn eq(&self, other: &Self) -> bool { self.pos == other.pos && self.dir == other.dir } } - impl<'a, T, D: Movement> std::hash::Hash for GridCursor<'a, T, D> { + impl std::hash::Hash for GridCursor<'_, T, D> { fn hash(&self, state: &mut H) { self.pos.hash(state); self.dir.hash(state); @@ -742,7 +742,7 @@ pub mod cursors { } } - impl<'a, T: std::fmt::Debug, D: Movement> std::fmt::Debug for GridCursor<'a, T, D> { + impl std::fmt::Debug for GridCursor<'_, T, D> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("GridCursor") .field("pos", &self.pos) @@ -816,7 +816,7 @@ pub mod cursors { } } - impl<'a, T: DirectedTile, D: Movement> Iterator for DirectedCursor<'a, T, D> { + impl, D: Movement> Iterator for DirectedCursor<'_, T, D> { type Item = (Position, D, T); fn next(&mut self) -> Option { @@ -905,7 +905,7 @@ pub mod cursors { } } - impl<'a, T: FillableTile> std::fmt::Debug for FloodFillCursor<'a, T> { + impl std::fmt::Debug for FloodFillCursor<'_, T> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FloodFillCursor") .field("visited", &self.visited) @@ -914,7 +914,7 @@ pub mod cursors { } } - impl<'a, T: FillableTile> Iterator for FloodFillCursor<'a, T> { + impl Iterator for FloodFillCursor<'_, T> { type Item = Position; fn next(&mut self) -> Option { diff --git a/utils/src/lib.rs b/utils/src/lib.rs index c201c42..22b5215 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -8,7 +8,6 @@ pub mod pos; pub mod range; #[allow(unused)] - pub mod prelude { pub use crate::dir::*; pub use crate::geom; diff --git a/utils/src/misc.rs b/utils/src/misc.rs index 37e3b57..8ffbede 100644 --- a/utils/src/misc.rs +++ b/utils/src/misc.rs @@ -18,25 +18,37 @@ pub enum FollowRangeResult { Increasing, Decreasing, Fluctuates, - ListTooShort + ListTooShort, } -pub fn follows_diff_range(l: &[i64], diff_range: Range, enforce_one_way: bool, allow_eq: bool) -> FollowRangeResult { +pub fn follows_diff_range( + l: &[i64], + diff_range: Range, + enforce_one_way: bool, + allow_eq: bool, +) -> FollowRangeResult { if l.len() < 2 { FollowRangeResult::ListTooShort } else { let first_diff = l[1] - l[0]; if diff_range.contains(&first_diff) { let mut ordering = FollowRangeResult::Fluctuates; - + let failing_pair = l.windows(2).skip(1).find_map(|w| { let (x, y) = (w[0], w[1]); let diff = y - x; if diff_range.contains(&diff) && (allow_eq || diff != 0) { if ordering == FollowRangeResult::Fluctuates && diff != 0 { - ordering = if diff < 0 { FollowRangeResult::Decreasing } else { FollowRangeResult::Increasing }; + ordering = if diff < 0 { + FollowRangeResult::Decreasing + } else { + FollowRangeResult::Increasing + }; None - } else if enforce_one_way && (ordering == FollowRangeResult::Increasing && diff < 0) || (ordering == FollowRangeResult::Decreasing && diff > 0) { + } else if enforce_one_way + && (ordering == FollowRangeResult::Increasing && diff < 0) + || (ordering == FollowRangeResult::Decreasing && diff > 0) + { Some((x, y)) } else { None @@ -48,7 +60,7 @@ pub fn follows_diff_range(l: &[i64], diff_range: Range, enforce_one_way: bo match failing_pair { Some((x, y)) => FollowRangeResult::InvalidPair(x, y), - None => ordering + None => ordering, } } else { FollowRangeResult::InvalidPair(l[0], l[1]) @@ -58,6 +70,8 @@ pub fn follows_diff_range(l: &[i64], diff_range: Range, enforce_one_way: bo pub fn all_combos_remove_one(l: &[T]) -> impl Iterator> { (0..l.len()).map(|exclude| { - l.iter().enumerate().filter_map(move |(i, e)| Some(e).filter(|_| i != exclude)) + l.iter() + .enumerate() + .filter_map(move |(i, e)| Some(e).filter(|_| i != exclude)) }) } diff --git a/years/2024/src/day_1.rs b/years/2024/src/day_1.rs index ee2e599..fb69760 100644 --- a/years/2024/src/day_1.rs +++ b/years/2024/src/day_1.rs @@ -13,7 +13,7 @@ impl Day for Day1 { r.sort_unstable(); Some(l.into_iter() - .zip(r.into_iter()) + .zip(r) .map(|(l, r)| (l - r).abs()) .sum::() .to_string() diff --git a/years/2024/src/day_2.rs b/years/2024/src/day_2.rs index 2ba69e8..073ebe8 100644 --- a/years/2024/src/day_2.rs +++ b/years/2024/src/day_2.rs @@ -14,15 +14,15 @@ impl Day for Day2 { day_stuff!(2, "2", "4", Vec>); fn part_1(input: Self::Input) -> Option { - Some(input.into_iter().filter(|v| line_valid(&v)).count().to_string()) + Some(input.into_iter().filter(|v| line_valid(v)).count().to_string()) } fn part_2(input: Self::Input) -> Option { Some(input.into_iter().filter(|line| { - line_valid(&line) || + line_valid(line) || all_combos_remove_one(line) .any(|combo| { - let v = combo.map(|x| *x).collect::>(); + let v = combo.copied().collect::>(); line_valid(&v) }) }).count().to_string())