Add structure for missing days

This commit is contained in:
Sebastian Knackstedt 2022-12-20 14:05:21 +01:00
parent e0900ec2ed
commit 47a7381575
Signed by: sebastian
GPG Key ID: CDCD9AF904D93EF7
7 changed files with 112 additions and 0 deletions

View File

@ -69,4 +69,23 @@ path = "src/day14/main.rs"
name = "day15"
path = "src/day15/main.rs"
[[bin]]
name = "day16"
path = "src/day16/main.rs"
[[bin]]
name = "day17"
path = "src/day17/main.rs"
[[bin]]
name = "day18"
path = "src/day18/main.rs"
[[bin]]
name = "day19"
path = "src/day19/main.rs"
[[bin]]
name = "day20"
path = "src/day20/main.rs"
[dependencies]

10
day16_test.txt Normal file
View File

@ -0,0 +1,10 @@
Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
Valve BB has flow rate=13; tunnels lead to valves CC, AA
Valve CC has flow rate=2; tunnels lead to valves DD, BB
Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE
Valve EE has flow rate=3; tunnels lead to valves FF, DD
Valve FF has flow rate=0; tunnels lead to valves EE, GG
Valve GG has flow rate=0; tunnels lead to valves FF, HH
Valve HH has flow rate=22; tunnel leads to valve GG
Valve II has flow rate=0; tunnels lead to valves AA, JJ
Valve JJ has flow rate=21; tunnel leads to valve II

71
src/day16/main.rs Normal file
View File

@ -0,0 +1,71 @@
use std::collections::{HashMap, HashSet};
use base::read_file;
#[derive(Debug)]
struct ScanEntry {
id: usize,
flow_rate: u32,
next: Vec<usize>,
}
fn find_path(graph: &HashMap<usize, ScanEntry>, start_id: usize, visited: &mut HashSet<usize>) {
if let Some(current) = graph.get(&start_id) {
visited.insert(current.id);
for next_id in &current.next {
if !visited.contains(next_id) {
println!("Found {}", next_id);
find_path(graph, *next_id, visited);
}
}
}
}
fn main() {
let lines = read_file("day16_test.txt");
let mut ids = HashMap::new();
let mut next_id = 0;
let mut entries = HashMap::new();
let mut start_id = None;
for line in lines {
let mut my_id = None;
let mut flow = None;
let mut next_ids = vec![];
for x in line.split([' ', ',']) {
if x.len() > 0 {
let mut uppercase = true;
for char in x.chars() {
uppercase = char.is_uppercase();
if !uppercase { break; };
}
if uppercase {
let id = *ids.entry(x.to_owned()).or_insert_with(|| {
next_id += 1;
next_id
});
match my_id {
None => my_id = Some(id),
Some(_) => next_ids.push(id),
}
match start_id {
None => start_id = Some(id),
_ => {}
}
} else if x.contains('=') {
let flow_value = x.split(['=', ';']).filter_map(|s| s.parse::<u32>().ok()).next().unwrap();
flow = Some(flow_value);
}
}
}
let entry = ScanEntry {
id: my_id.unwrap(),
flow_rate: flow.unwrap(),
next: next_ids,
};
entries.insert(entry.id, entry);
}
let mut visited = HashSet::new();
dbg!(&entries);
find_path(&entries, start_id.unwrap(), &mut visited);
}

3
src/day17/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Not ready");
}

3
src/day18/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Not ready");
}

3
src/day19/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Not ready");
}

3
src/day20/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Not ready");
}