Reformatted

This commit is contained in:
2023-05-26 10:02:22 +02:00
parent b922b808fc
commit cfb3ae497e
7 changed files with 29 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
use std::collections::HashSet;
use crate::utils; use crate::utils;
use std::collections::HashSet;
pub fn task1() { pub fn task1() {
let frequency: i32 = utils::read_file("input/day01.txt") let frequency: i32 = utils::read_file("input/day01.txt")
@@ -23,7 +23,8 @@ pub fn task2() {
} else { } else {
Some((*current, true)) Some((*current, true))
} }
}).find(|state| state.1); })
.find(|state| state.1);
println!("Part 2: {} was there already!", final_state.unwrap().0); println!("Part 2: {} was there already!", final_state.unwrap().0);
} }

View File

@@ -1,6 +1,6 @@
use crate::utils;
use regex::Regex; use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use crate::utils;
#[derive(PartialEq)] #[derive(PartialEq)]
enum Use { enum Use {
@@ -23,7 +23,8 @@ pub fn task1() {
let width: u32 = m.get(4).unwrap().as_str().parse().unwrap(); let width: u32 = m.get(4).unwrap().as_str().parse().unwrap();
let height: u32 = m.get(5).unwrap().as_str().parse().unwrap(); let height: u32 = m.get(5).unwrap().as_str().parse().unwrap();
(id, left, top, width, height) (id, left, top, width, height)
}).fold( })
.fold(
HashMap::<(u32, u32), Use>::new(), HashMap::<(u32, u32), Use>::new(),
|mut map, (id, left, top, width, height)| { |mut map, (id, left, top, width, height)| {
for x in left..left + width { for x in left..left + width {
@@ -38,7 +39,8 @@ pub fn task1() {
map map
}, },
).iter() )
.iter()
.filter(|it| *it.1 == Use::Multi) .filter(|it| *it.1 == Use::Multi)
.count(); .count();
@@ -60,7 +62,8 @@ pub fn task2() {
let width: u32 = m.get(4).unwrap().as_str().parse().unwrap(); let width: u32 = m.get(4).unwrap().as_str().parse().unwrap();
let height: u32 = m.get(5).unwrap().as_str().parse().unwrap(); let height: u32 = m.get(5).unwrap().as_str().parse().unwrap();
(id, left, top, width, height) (id, left, top, width, height)
}).collect(); })
.collect();
let distribution: HashMap<(u32, u32), Use> = claims.iter().fold( let distribution: HashMap<(u32, u32), Use> = claims.iter().fold(
HashMap::<(u32, u32), Use>::new(), HashMap::<(u32, u32), Use>::new(),
@@ -90,7 +93,8 @@ pub fn task2() {
} }
} }
true true
}).unwrap(); })
.unwrap();
println!("Part 2: {}", winner_id); println!("Part 2: {}", winner_id);
} }

View File

@@ -1,8 +1,8 @@
use crate::utils;
use chrono::prelude::*; use chrono::prelude::*;
use chrono::Duration; use chrono::Duration;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use std::collections::HashMap; use std::collections::HashMap;
use crate::utils;
enum Activity { enum Activity {
Starts(u32), Starts(u32),
@@ -35,7 +35,8 @@ pub fn task1() {
Activity::Starts(number) Activity::Starts(number)
}; };
(time, activity) (time, activity)
}).collect(); })
.collect();
input.sort_by_key(|it| it.0); input.sort_by_key(|it| it.0);
let mut current_id: u32 = 0; let mut current_id: u32 = 0;
@@ -104,7 +105,8 @@ pub fn task2() {
Activity::Starts(number) Activity::Starts(number)
}; };
(time, activity) (time, activity)
}).collect(); })
.collect();
input.sort_by_key(|it| it.0); input.sort_by_key(|it| it.0);
let mut current_id: u32 = 0; let mut current_id: u32 = 0;

View File

@@ -1,5 +1,5 @@
use std::time::Instant;
use crate::utils; use crate::utils;
use std::time::Instant;
pub fn task1() { pub fn task1() {
let mut input = utils::read_file("input/day05.txt"); let mut input = utils::read_file("input/day05.txt");
@@ -24,9 +24,11 @@ pub fn task2() {
.chars() .chars()
.filter(|ch| ch.eq_ignore_ascii_case(&c)) .filter(|ch| ch.eq_ignore_ascii_case(&c))
.collect::<String>(), .collect::<String>(),
).len(),
) )
}).min_by_key(|it| it.1) .len(),
)
})
.min_by_key(|it| it.1)
.unwrap(); .unwrap();
println!("Duration: {:?}", Instant::now() - start); println!("Duration: {:?}", Instant::now() - start);
@@ -56,6 +58,7 @@ fn reduce(input: &str) -> String {
stack.push(c); stack.push(c);
} }
stack stack
}).iter() })
.iter()
.collect() .collect()
} }

View File

@@ -18,7 +18,8 @@ pub fn task1() {
let mut open: HashSet<char> = tasks let mut open: HashSet<char> = tasks
.iter() .iter()
.filter(|task| !depends_on.contains_key(task)).copied() .filter(|task| !depends_on.contains_key(task))
.copied()
.collect(); .collect();
let mut result = String::new(); let mut result = String::new();

View File

@@ -200,7 +200,8 @@ impl Game {
// None // None
// } // }
let map = Map::from_game(self, from); let map = Map::from_game(self, from);
map.shortest_path(from, to).map(|path| *path.get(1).unwrap_or(&from)) map.shortest_path(from, to)
.map(|path| *path.get(1).unwrap_or(&from))
} }
/// Returns true if a full round was played, false if the round aborted because all /// Returns true if a full round was played, false if the round aborted because all

View File

@@ -164,10 +164,7 @@ impl Cave {
}) })
.for_each(|node| { .for_each(|node| {
if self.equipment_allowed_for_region(node.0, node.1, node.2) { if self.equipment_allowed_for_region(node.0, node.1, node.2) {
result.push(Edge { result.push(Edge { cost: 1, node })
cost: 1,
node,
})
} }
}); });