From 5778c56d166840bdc65be030471a4ee6d82f7c7e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 12 Nov 2024 18:33:11 +0100 Subject: [PATCH] ci: lint --- src/bin/01.rs | 65 +++++++++++++++++++++++---------------------------- src/main.rs | 6 ++++- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/bin/01.rs b/src/bin/01.rs index d7605c1..2fa73ec 100644 --- a/src/bin/01.rs +++ b/src/bin/01.rs @@ -6,7 +6,6 @@ advent_of_code::solution!(1); use std::collections::HashSet; use std::hash::Hash; - #[derive(Debug, Copy, Clone)] enum Turn { Left, @@ -32,19 +31,19 @@ struct Pos { impl Pos { fn walk_north(&mut self, length: u32) { - self.y = self.y.saturating_add_unsigned(length); + self.y = self.y.saturating_add_unsigned(length); } fn walk_south(&mut self, length: u32) { - self.y = self.y.saturating_sub_unsigned(length); + self.y = self.y.saturating_sub_unsigned(length); } fn walk_west(&mut self, length: u32) { - self.x = self.x.saturating_sub_unsigned(length); + self.x = self.x.saturating_sub_unsigned(length); } fn walk_east(&mut self, length: u32) { - self.x = self.x.saturating_add_unsigned(length); + self.x = self.x.saturating_add_unsigned(length); } fn distance_to_origin(self) -> u32 { @@ -63,10 +62,7 @@ struct State { impl State { fn init() -> Self { Self { - pos: Pos { - x: 0, - y: 0, - }, + pos: Pos { x: 0, y: 0 }, dir: FaceDir::N, } } @@ -98,16 +94,16 @@ impl State { }; } - fn next_location(&mut self, step: &Step) -> Self { + fn next_location(&mut self, step: &Step) -> Self { match step { Step(Turn::Left, length) => { self.turn_left(); self.walk_for(*length); - }, + } Step(Turn::Right, length) => { self.turn_right(); self.walk_for(*length); - }, + } }; *self } @@ -117,22 +113,24 @@ impl State { Step(Turn::Left, length) => { self.turn_left(); length - }, + } Step(Turn::Right, length) => { self.turn_right(); length } }; - (0..(*length)).map(|_| { - self.walk_for(1); - self.pos - }).collect() + (0..(*length)) + .map(|_| { + self.walk_for(1); + self.pos + }) + .collect() } fn visit_locations(self, steps: Vec) -> Self { - steps - .into_iter() - .fold(self, |mut state, step| State::next_location(&mut state, &step)) + steps.into_iter().fold(self, |mut state, step| { + State::next_location(&mut state, &step) + }) } fn scan_steps(&mut self, steps: Vec) -> Vec { @@ -156,28 +154,24 @@ fn first_repeated_loc(vec: &Vec) -> Option<&Pos> { None } - fn parse_input(_input: &str) -> Vec { _input .to_string() .strip_suffix("\n") .unwrap_or(&_input) .split(", ") - .map(|s| - { - let (direction, value) = s.split_at(1); - let length: u32 = value.parse().expect( - &format!( - "invalid length! {:?}", - value - ).to_string()); - match direction { - "L" => Step(Turn::Left, length), - "R" => Step(Turn::Right, length), - _ => panic!("invalid turn direction!"), - } + .map(|s| { + let (direction, value) = s.split_at(1); + let length: u32 = value + .parse() + .expect(&format!("invalid length! {:?}", value).to_string()); + match direction { + "L" => Step(Turn::Left, length), + "R" => Step(Turn::Right, length), + _ => panic!("invalid turn direction!"), } - ).collect() + }) + .collect() } pub fn part_one(input: &str) -> Option { @@ -214,4 +208,3 @@ mod tests { assert_eq!(result, Some(4)); } } - diff --git a/src/main.rs b/src/main.rs index 0ee1c39..2a360fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,7 +106,11 @@ fn main() { AppArguments::Time { day, all, store } => time::handle(day, all, store), AppArguments::Download { day } => download::handle(day), AppArguments::Read { day } => read::handle(day), - AppArguments::Scaffold { day, download, overwrite } => { + AppArguments::Scaffold { + day, + download, + overwrite, + } => { scaffold::handle(day, overwrite); if download { download::handle(day);