diff --git a/src/bin/2023/02.rs b/src/bin/2023/02.rs index 19cf441..932368e 100644 --- a/src/bin/2023/02.rs +++ b/src/bin/2023/02.rs @@ -42,11 +42,7 @@ impl Round { ok } fn power(&self) -> u64 { - let mut sack = Sack { - reds: 0, - greens: 0, - blues: 0, - }; + let mut sack = Sack { reds: 0, greens: 0, blues: 0 }; for take in self.takes.clone() { if take.red > sack.reds { sack.reds = take.red @@ -70,11 +66,7 @@ impl From<&str> for Round { takes: Vec::::new(), }; for taking in value.get(doublecolon + 1..).unwrap().split(";") { - let mut take = Take { - red: 0, - green: 0, - blue: 0, - }; + let mut take = Take { red: 0, green: 0, blue: 0 }; for color in taking.split(',').map(str::trim) { let mut i = color.splitn(2, char::is_whitespace); let amount = parsenumber(i.next().unwrap()); @@ -96,11 +88,7 @@ fn main() { for game in DATA.split('\n') { gamerounds.push(game.into()); } - let sack = Sack { - reds: 12, - greens: 13, - blues: 14, - }; + let sack = Sack { reds: 12, greens: 13, blues: 14 }; let mut sum = 0; for round in gamerounds.clone() { if round.possible(sack) { diff --git a/src/bin/2024/01.rs b/src/bin/2024/01.rs index 5356d1c..1798e6d 100644 --- a/src/bin/2024/01.rs +++ b/src/bin/2024/01.rs @@ -7,10 +7,7 @@ include_data!(DATA 2024 01); pub fn splitspace(input: &str) -> (u32, u32) { println!("{}", input); let mut output = input.split_ascii_whitespace(); - ( - parsenumber(output.next().unwrap()), - parsenumber(output.next().unwrap()), - ) + (parsenumber(output.next().unwrap()), parsenumber(output.next().unwrap())) } fn distance(leftlist: &Vec, rightlist: &Vec) -> u32 { diff --git a/src/bin/2024/03.rs b/src/bin/2024/03.rs index db64628..ee82bbe 100644 --- a/src/bin/2024/03.rs +++ b/src/bin/2024/03.rs @@ -34,8 +34,8 @@ fn main() { let a = parsenumber::(capture.name("i").unwrap().as_str()); let b = parsenumber::(capture.name("j").unwrap().as_str()); sum += a * b - } - (_, _) => {} + }, + (_, _) => {}, } } println!("The Cleaned with check output is: {}", sum); diff --git a/src/bin/2024/06.rs b/src/bin/2024/06.rs index 359d968..a585347 100644 --- a/src/bin/2024/06.rs +++ b/src/bin/2024/06.rs @@ -18,23 +18,13 @@ struct DirectionalKartesian { } impl From<(Kartesian, KartesianDirection)> for DirectionalKartesian { fn from(value: (Kartesian, KartesianDirection)) -> Self { - DirectionalKartesian { - x: value.0.x, - y: value.0.y, - dir: value.1, - } + DirectionalKartesian { x: value.0.x, y: value.0.y, dir: value.1 } } } impl Into<(Kartesian, KartesianDirection)> for &DirectionalKartesian { fn into(self) -> (Kartesian, KartesianDirection) { - ( - Kartesian { - x: self.x, - y: self.y, - }, - self.dir, - ) + (Kartesian { x: self.x, y: self.y }, self.dir) } } @@ -62,19 +52,15 @@ fn find_guard(map: Table) -> Kartesian { fn get_path(map: Table) -> Vec> { let mut position = (find_guard(map.clone()), KartesianDirection::Top); let maximum = Kartesian::new(map.len() as i32, map[0].len() as i32); - debug!( - "Guard is on coordinate {}:{}", - position.0.x + 1, - position.0.y + 1 - ); + debug!("Guard is on coordinate {}:{}", position.0.x + 1, position.0.y + 1); let mut passed = Vec::new(); passed.push(position.into()); loop { - position.0 = match position.0.checked_add_max(position.1.vector(), maximum) { + position.0 = match position.0.checked_add_max(position.1.vector().into(), maximum) { None => { debug!("Guard left the space after {} steps", passed.len()); return passed; - } + }, Some(pos) => pos, }; if map[position.0.x as usize][position.0.y as usize] != '#' { @@ -82,33 +68,26 @@ fn get_path(map: Table) -> Vec> { continue; } position.0 -= position.1.vector(); - debug!( - "Guard turned right on {}:{}", - position.0.x + 1, - position.0.y + 1 - ); + debug!("Guard turned right on {}:{}", position.0.x + 1, position.0.y + 1); position.1 = position.1.clockwise(false); } } fn solver1(input: &str) -> usize { - let map = convert_to_array(input, line_to_char); + let map = convert_to_array::<_, _, '\n'>(input, line_to_char); let mut path = get_path(map); path.sort(); path.dedup_by_key(|p| (p.x, p.y)); path.len() } -fn is_looping( - path: Vec>, - start_point: DirectionalKartesian, -) -> bool { +fn is_looping(_path: Vec>, _start_point: DirectionalKartesian) -> bool { false } #[allow(unused_variables, unused_mut)] fn solver2(input: &str) -> usize { - let map = convert_to_array(input, line_to_char); + let map = convert_to_array::<_, _, '\n'>(input, line_to_char); let maximum = Kartesian::new(map.len() as i32, map[0].len() as i32); let mut path = get_path(map.clone()); let mut p = path.iter(); @@ -123,10 +102,7 @@ fn solver2(input: &str) -> usize { currentpoint = point.into(); currentpoint.1 = currentpoint.1.clockwise(false); loop { - currentpoint.0 = match currentpoint - .0 - .checked_add_max(currentpoint.1.vector(), maximum) - { + currentpoint.0 = match currentpoint.0.checked_add_max(currentpoint.1.vector(), maximum) { None => break, Some(p) => p, }; @@ -145,14 +121,8 @@ fn solver2(input: &str) -> usize { } fn main() { - println!( - "Guard left the space after walking through {} distinct positions", - solver1(DATA) - ); - println!( - "There are {} positions that are good for loops", - solver2(DATA) - ); + println!("Guard left the space after walking through {} distinct positions", solver1(DATA)); + println!("There are {} positions that are good for loops", solver2(DATA)); } #[cfg(test)] diff --git a/src/bin/2024/07.rs b/src/bin/2024/07.rs index eac9623..e6d840f 100644 --- a/src/bin/2024/07.rs +++ b/src/bin/2024/07.rs @@ -19,27 +19,14 @@ enum Operation { } impl Operation { - fn op< - T: Integer - + Add - + Mul - + Pow - + std::ops::DivAssign - + AddAssign - + From - + Copy, - >( - self, - a: T, - b: T, - ) -> T { + fn op + std::ops::DivAssign + AddAssign + From + Copy>(self, a: T, b: T) -> T { match self { Operation::Add => a + b, Operation::Multiply => a * b, Operation::Concat => { let ta = a * T::from(10).pow(numberlength(b)); ta + b - } + }, } } } @@ -47,10 +34,7 @@ impl Operation { fn get_data(line: &str) -> (u64, Vec) { let (result, numbers) = line.split_once(':').unwrap(); - ( - parsenumber(result.trim()), - Vec::from(convert_to_array::<_, _, ' '>(numbers, parsenumber)), - ) + (parsenumber(result.trim()), Vec::from(convert_to_array::<_, _, ' '>(numbers, parsenumber))) } fn test_equation(result: u64, numbers: Vec, ops: Vec) -> bool { @@ -87,7 +71,11 @@ fn get_ops(len: usize, conf: usize) -> Vec { fn get_ops_with_concat(len: u32) -> Vec> { let mut ops = Vec::with_capacity(3u64.saturating_pow(len) as usize); - for i in [Operation::Add, Operation::Concat, Operation::Multiply] { + for i in [ + Operation::Add, + Operation::Concat, + Operation::Multiply, + ] { if len > 1 { for mut oplist in get_ops_with_concat(len - 1) { oplist.insert(0, i); @@ -146,32 +134,56 @@ mod test { for c in [ ( 190, - Vec::from([10, 19]), + Vec::from([ + 10, 19, + ]), Vec::from([Operation::Multiply]), true, ), ( 3267, - Vec::from([81, 40, 27]), - Vec::from([Operation::Add, Operation::Multiply]), + Vec::from([ + 81, 40, 27, + ]), + Vec::from([ + Operation::Add, + Operation::Multiply, + ]), true, ), ( 3267, - Vec::from([81, 40, 27]), - Vec::from([Operation::Multiply, Operation::Add]), + Vec::from([ + 81, 40, 27, + ]), + Vec::from([ + Operation::Multiply, + Operation::Add, + ]), true, ), ( 292, - Vec::from([11, 6, 16, 20]), - Vec::from([Operation::Add, Operation::Multiply, Operation::Add]), + Vec::from([ + 11, 6, 16, 20, + ]), + Vec::from([ + Operation::Add, + Operation::Multiply, + Operation::Add, + ]), true, ), ( 292, - Vec::from([11, 6, 16, 20]), - Vec::from([Operation::Add, Operation::Multiply, Operation::Multiply]), + Vec::from([ + 11, 6, 16, 20, + ]), + Vec::from([ + Operation::Add, + Operation::Multiply, + Operation::Multiply, + ]), false, ), ] { diff --git a/src/bin/2024/09.rs b/src/bin/2024/09.rs index 0d96eff..8705fe5 100644 --- a/src/bin/2024/09.rs +++ b/src/bin/2024/09.rs @@ -136,14 +136,8 @@ fn main() { let mut file_disk = raw_disk.clone(); compact_blocks(&mut block_disk); let mut cksum = calculate_checksum(block_disk); - println!( - "Checksum for the blockcompacted disk is: {}", - cksum - ); + println!("Checksum for the blockcompacted disk is: {}", cksum); compact_files(&mut file_disk); cksum = calculate_checksum(file_disk); - println!( - "Checksum for the filecompacted disk is: {}", - cksum, - ); + println!("Checksum for the filecompacted disk is: {}", cksum,); } diff --git a/src/coordinate_systems/kartesian.rs b/src/coordinate_systems/kartesian.rs index 8d6fa25..aa3954f 100644 --- a/src/coordinate_systems/kartesian.rs +++ b/src/coordinate_systems/kartesian.rs @@ -352,12 +352,12 @@ impl KartesianDirection { } } - pub fn iter(none: bool, diagonal: bool, nondiagonal: bool) -> KartesianIterator { + pub fn iter(none: bool, diagonal: bool, straight: bool) -> KartesianIterator { KartesianIterator { i: 0, - none: none, - diagonal: diagonal, - nondiagonal: nondiagonal, + none, + diagonal, + straight, } } } @@ -383,7 +383,7 @@ pub struct KartesianIterator { i: u8, diagonal: bool, none: bool, - nondiagonal: bool, + straight: bool, } impl Iterator for KartesianIterator { @@ -391,7 +391,7 @@ impl Iterator for KartesianIterator { fn next(&mut self) -> Option { let mut i = self.i; - if self.nondiagonal { + if self.straight { if i < 4 { self.i += 1; }