Add structure for missing days

This commit is contained in:
2022-12-20 14:05:21 +01:00
parent e0900ec2ed
commit 47a7381575
7 changed files with 112 additions and 0 deletions

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");
}