2022 day 16 wip
This commit is contained in:
parent
1522be4221
commit
364c247799
|
@ -1,3 +1,4 @@
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,12 +14,46 @@ pub fn run() -> () {
|
||||||
|
|
||||||
struct Valve<'data> {
|
struct Valve<'data> {
|
||||||
name: &'data str,
|
name: &'data str,
|
||||||
rate: u8,
|
rate: u32,
|
||||||
next: Vec<&'data str>
|
next: Vec<&'data str>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn solve1(data: &[Valve]) -> i32 {
|
fn build_map<'data, 'a>(valves: &'a [Valve<'data>]) -> HashMap<&'data str, &'a Valve<'data>> {
|
||||||
|
valves.iter().map(|valve| (valve.name, valve)).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn released_pressure<'data, 'a>(map: &'a HashMap<&'data str, Valve>, keys: &'a [&'data str]) -> u32 {
|
||||||
|
keys.iter()
|
||||||
|
.map(|&key| map.get(key).unwrap().rate)
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn valve_move<'data, 'a>(
|
||||||
|
map: &'a HashMap<&'data str, &'a Valve<'data>>,
|
||||||
|
open: HashSet<&'data str>,
|
||||||
|
next: &'data str,
|
||||||
|
time_left: u8,
|
||||||
|
released: u32,
|
||||||
|
) -> i32 {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn valve_open<'data, 'a>(
|
||||||
|
valves: HashMap<&'data str, &'a Valve<'data>>,
|
||||||
|
open: HashSet<&'data str>,
|
||||||
|
next: &'data str,
|
||||||
|
time_left: u8,
|
||||||
|
released: u32,
|
||||||
|
) -> i32 {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn solve1(data: &[Valve]) -> u32 {
|
||||||
|
let map = build_map(data);
|
||||||
|
|
||||||
|
valve_move(&map, HashSet::new(), "AA", 30, 0);
|
||||||
|
println!("hi");
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +72,7 @@ fn parse_data<T: AsRef<str>>(data: &[T]) -> Vec<Valve> {
|
||||||
.next().unwrap()
|
.next().unwrap()
|
||||||
.split(";")
|
.split(";")
|
||||||
.next().unwrap()
|
.next().unwrap()
|
||||||
.parse::<u8>().unwrap();
|
.parse().unwrap();
|
||||||
let next = line.skip(4)
|
let next = line.skip(4)
|
||||||
.map(|str| str.split(",").next().unwrap())
|
.map(|str| str.split(",").next().unwrap())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
Loading…
Reference in a new issue