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

View File

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

View File

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

View File

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

View File

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

View File

@@ -200,7 +200,8 @@ impl Game {
// None
// }
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

View File

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