Advent of Code solutions
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Linting

Ben C 1f36f8fb db70ca7f

+34 -19
+2
.cargo/config.toml
··· 1 + [alias] 2 + lint = "clippy -- -D warnings"
+1 -1
src/main.rs
··· 19 19 fn main() { 20 20 let args = std::env::args().skip(1).collect::<Vec<_>>(); 21 21 22 - let command = args.get(0); 22 + let command = args.first(); 23 23 24 24 match command { 25 25 Some(command) => match command.as_str() {
+6 -6
utils/src/grid.rs
··· 706 706 } 707 707 } 708 708 709 - impl<'a, T, D: Movement> PartialEq for GridCursor<'a, T, D> { 709 + impl<T, D: Movement> PartialEq for GridCursor<'_, T, D> { 710 710 fn eq(&self, other: &Self) -> bool { 711 711 self.pos == other.pos && self.dir == other.dir 712 712 } 713 713 } 714 714 715 - impl<'a, T, D: Movement> std::hash::Hash for GridCursor<'a, T, D> { 715 + impl<T, D: Movement> std::hash::Hash for GridCursor<'_, T, D> { 716 716 fn hash<H: Hasher>(&self, state: &mut H) { 717 717 self.pos.hash(state); 718 718 self.dir.hash(state); ··· 742 742 } 743 743 } 744 744 745 - impl<'a, T: std::fmt::Debug, D: Movement> std::fmt::Debug for GridCursor<'a, T, D> { 745 + impl<T: std::fmt::Debug, D: Movement> std::fmt::Debug for GridCursor<'_, T, D> { 746 746 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 747 747 f.debug_struct("GridCursor") 748 748 .field("pos", &self.pos) ··· 816 816 } 817 817 } 818 818 819 - impl<'a, T: DirectedTile<D>, D: Movement> Iterator for DirectedCursor<'a, T, D> { 819 + impl<T: DirectedTile<D>, D: Movement> Iterator for DirectedCursor<'_, T, D> { 820 820 type Item = (Position, D, T); 821 821 822 822 fn next(&mut self) -> Option<Self::Item> { ··· 905 905 } 906 906 } 907 907 908 - impl<'a, T: FillableTile> std::fmt::Debug for FloodFillCursor<'a, T> { 908 + impl<T: FillableTile> std::fmt::Debug for FloodFillCursor<'_, T> { 909 909 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 910 910 f.debug_struct("FloodFillCursor") 911 911 .field("visited", &self.visited) ··· 914 914 } 915 915 } 916 916 917 - impl<'a, T: FillableTile> Iterator for FloodFillCursor<'a, T> { 917 + impl<T: FillableTile> Iterator for FloodFillCursor<'_, T> { 918 918 type Item = Position; 919 919 920 920 fn next(&mut self) -> Option<Self::Item> {
-1
utils/src/lib.rs
··· 8 8 pub mod range; 9 9 10 10 #[allow(unused)] 11 - 12 11 pub mod prelude { 13 12 pub use crate::dir::*; 14 13 pub use crate::geom;
+21 -7
utils/src/misc.rs
··· 18 18 Increasing, 19 19 Decreasing, 20 20 Fluctuates, 21 - ListTooShort 21 + ListTooShort, 22 22 } 23 23 24 - pub fn follows_diff_range(l: &[i64], diff_range: Range<i64>, enforce_one_way: bool, allow_eq: bool) -> FollowRangeResult { 24 + pub fn follows_diff_range( 25 + l: &[i64], 26 + diff_range: Range<i64>, 27 + enforce_one_way: bool, 28 + allow_eq: bool, 29 + ) -> FollowRangeResult { 25 30 if l.len() < 2 { 26 31 FollowRangeResult::ListTooShort 27 32 } else { 28 33 let first_diff = l[1] - l[0]; 29 34 if diff_range.contains(&first_diff) { 30 35 let mut ordering = FollowRangeResult::Fluctuates; 31 - 36 + 32 37 let failing_pair = l.windows(2).skip(1).find_map(|w| { 33 38 let (x, y) = (w[0], w[1]); 34 39 let diff = y - x; 35 40 if diff_range.contains(&diff) && (allow_eq || diff != 0) { 36 41 if ordering == FollowRangeResult::Fluctuates && diff != 0 { 37 - ordering = if diff < 0 { FollowRangeResult::Decreasing } else { FollowRangeResult::Increasing }; 42 + ordering = if diff < 0 { 43 + FollowRangeResult::Decreasing 44 + } else { 45 + FollowRangeResult::Increasing 46 + }; 38 47 None 39 - } else if enforce_one_way && (ordering == FollowRangeResult::Increasing && diff < 0) || (ordering == FollowRangeResult::Decreasing && diff > 0) { 48 + } else if enforce_one_way 49 + && (ordering == FollowRangeResult::Increasing && diff < 0) 50 + || (ordering == FollowRangeResult::Decreasing && diff > 0) 51 + { 40 52 Some((x, y)) 41 53 } else { 42 54 None ··· 48 60 49 61 match failing_pair { 50 62 Some((x, y)) => FollowRangeResult::InvalidPair(x, y), 51 - None => ordering 63 + None => ordering, 52 64 } 53 65 } else { 54 66 FollowRangeResult::InvalidPair(l[0], l[1]) ··· 58 70 59 71 pub fn all_combos_remove_one<T>(l: &[T]) -> impl Iterator<Item = impl Iterator<Item = &T>> { 60 72 (0..l.len()).map(|exclude| { 61 - l.iter().enumerate().filter_map(move |(i, e)| Some(e).filter(|_| i != exclude)) 73 + l.iter() 74 + .enumerate() 75 + .filter_map(move |(i, e)| Some(e).filter(|_| i != exclude)) 62 76 }) 63 77 }
+1 -1
years/2024/src/day_1.rs
··· 13 13 r.sort_unstable(); 14 14 15 15 Some(l.into_iter() 16 - .zip(r.into_iter()) 16 + .zip(r) 17 17 .map(|(l, r)| (l - r).abs()) 18 18 .sum::<i32>() 19 19 .to_string()
+3 -3
years/2024/src/day_2.rs
··· 14 14 day_stuff!(2, "2", "4", Vec<Vec<i64>>); 15 15 16 16 fn part_1(input: Self::Input) -> Option<String> { 17 - Some(input.into_iter().filter(|v| line_valid(&v)).count().to_string()) 17 + Some(input.into_iter().filter(|v| line_valid(v)).count().to_string()) 18 18 } 19 19 20 20 fn part_2(input: Self::Input) -> Option<String> { 21 21 Some(input.into_iter().filter(|line| { 22 - line_valid(&line) || 22 + line_valid(line) || 23 23 all_combos_remove_one(line) 24 24 .any(|combo| { 25 - let v = combo.map(|x| *x).collect::<Vec<_>>(); 25 + let v = combo.copied().collect::<Vec<_>>(); 26 26 line_valid(&v) 27 27 }) 28 28 }).count().to_string())