diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..92c7bd6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_size = 4 +indent_style = space +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = truew + +[Makefile] +indent_style = tab diff --git a/src/bin/2023/02.rs b/src/bin/2023/02.rs index 932368e..19cf441 100644 --- a/src/bin/2023/02.rs +++ b/src/bin/2023/02.rs @@ -42,7 +42,11 @@ 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 @@ -66,7 +70,11 @@ 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()); @@ -88,7 +96,11 @@ 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/04.rs b/src/bin/2024/04.rs index 99b708c..a646fb3 100644 --- a/src/bin/2024/04.rs +++ b/src/bin/2024/04.rs @@ -49,7 +49,10 @@ fn get_x(list: Vec) -> usize { fn follow_text(data: &Table, start_point: Kartesian, direction: KartesianDirection, current_pos: Kartesian, chars: Vec, list: &mut Vec) { let mut iter = chars.iter().cloned(); match iter.next() { - None => list.push(TextPos { start: start_point, end: current_pos }), + None => list.push(TextPos { + start: start_point, + end: current_pos, + }), Some(c) => match current_pos.move_dir_max(direction.vector_abs(), direction, Kartesian::maximum(data)) { None => return, Some(new) => { diff --git a/src/bin/2024/06.rs b/src/bin/2024/06.rs index a585347..4ae6439 100644 --- a/src/bin/2024/06.rs +++ b/src/bin/2024/06.rs @@ -18,13 +18,23 @@ 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, + ) } } diff --git a/src/bin/2024/11.rs b/src/bin/2024/11.rs index 1e4fb4b..23204d4 100644 --- a/src/bin/2024/11.rs +++ b/src/bin/2024/11.rs @@ -40,10 +40,13 @@ impl StoneCounter { fn new(start_values: Vec, rounds: usize) -> StoneCounter { let mut cache = Vec::with_capacity(start_values.len()); for v in start_values.iter() { - cache.push(Stone { number: *v, left: rounds }); + cache.push(Stone { + number: *v, + left: rounds, + }); } StoneCounter { - cache: cache, + cache, map: HashMap::with_capacity(10_000), stones: 0, start: rounds, @@ -72,7 +75,10 @@ impl StoneCounter { stone.left -= skip.skipped_steps; } stone.number = skip.newnumber_a; - self.cache.push(Stone { number: skip.newnumber_b, left: stone.left }); + self.cache.push(Stone { + number: skip.newnumber_b, + left: stone.left, + }); continue; }, ExtendedOption::Unset => {}, diff --git a/src/bin/2024/14.rs b/src/bin/2024/14.rs index 25b0460..0a608c5 100644 --- a/src/bin/2024/14.rs +++ b/src/bin/2024/14.rs @@ -108,18 +108,54 @@ mod test { #[test] fn test_safety() { let positions = vec![ - Kartesian { x: 5, y: 3 }, - Kartesian { x: 4, y: 5 }, - Kartesian { x: 0, y: 9 }, - Kartesian { x: 5, y: 4 }, - Kartesian { x: 6, y: 1 }, - Kartesian { x: 3, y: 1 }, - Kartesian { x: 0, y: 6 }, - Kartesian { x: 3, y: 2 }, - Kartesian { x: 2, y: 0 }, - Kartesian { x: 0, y: 6 }, - Kartesian { x: 5, y: 4 }, - Kartesian { x: 6, y: 6 }, + Kartesian { + x: 5, + y: 3, + }, + Kartesian { + x: 4, + y: 5, + }, + Kartesian { + x: 0, + y: 9, + }, + Kartesian { + x: 5, + y: 4, + }, + Kartesian { + x: 6, + y: 1, + }, + Kartesian { + x: 3, + y: 1, + }, + Kartesian { + x: 0, + y: 6, + }, + Kartesian { + x: 3, + y: 2, + }, + Kartesian { + x: 2, + y: 0, + }, + Kartesian { + x: 0, + y: 6, + }, + Kartesian { + x: 5, + y: 4, + }, + Kartesian { + x: 6, + y: 6, + }, ]; assert_eq!(calc_safety(positions, Kartesian::new(7, 11)), (1, 3, 4, 1)); } diff --git a/src/bin/2024/16.rs b/src/bin/2024/16.rs index 8885e3e..9cfdf0a 100644 --- a/src/bin/2024/16.rs +++ b/src/bin/2024/16.rs @@ -87,11 +87,8 @@ fn main() { let map = Map::from(convert_to_array::<_, _, '\n'>(DATA, line_to_char)); //println!("Startmap: \n{}", map); let deer = find_character(&map, 'S'); - let best = search_end(&map, deer, KartesianDirection::Right); - println!( - "Best Score is: {}", - best - ) + let best = search_end(&map, deer, KartesianDirection::East); + println!("Best Score is: {}", best) } #[cfg(test)]