Day 16 - init & parsing

This commit is contained in:
Jonathan Flueren 2022-12-16 12:18:42 +01:00
parent feccd2992a
commit 4e535dfdb6
4 changed files with 100 additions and 1 deletions

58
res/16/input.txt Normal file
View file

@ -0,0 +1,58 @@
Valve YK has flow rate=0; tunnels lead to valves GL, FT
Valve QA has flow rate=0; tunnels lead to valves JX, FD
Valve LN has flow rate=0; tunnels lead to valves FD, FG
Valve AU has flow rate=0; tunnels lead to valves BD, PQ
Valve MM has flow rate=0; tunnels lead to valves UL, AA
Valve JX has flow rate=0; tunnels lead to valves QA, NZ
Valve CV has flow rate=0; tunnels lead to valves UP, QW
Valve UZ has flow rate=0; tunnels lead to valves FG, NZ
Valve BP has flow rate=0; tunnels lead to valves TI, DX
Valve NS has flow rate=0; tunnels lead to valves ZL, CW
Valve CO has flow rate=0; tunnels lead to valves BD, AT
Valve RZ has flow rate=0; tunnels lead to valves AA, ZO
Valve PQ has flow rate=0; tunnels lead to valves ML, AU
Valve CW has flow rate=7; tunnels lead to valves UL, PH, OF, NS, GT
Valve FG has flow rate=14; tunnels lead to valves SO, JR, IN, LN, UZ
Valve EZ has flow rate=0; tunnels lead to valves UP, QP
Valve GN has flow rate=0; tunnels lead to valves VQ, CH
Valve QW has flow rate=6; tunnels lead to valves CV, PF, KH, UY, TI
Valve UL has flow rate=0; tunnels lead to valves MM, CW
Valve VQ has flow rate=12; tunnels lead to valves GN, LC
Valve FT has flow rate=0; tunnels lead to valves SG, YK
Valve SG has flow rate=21; tunnels lead to valves FT, LC, NO, QX
Valve BD has flow rate=23; tunnels lead to valves CO, AU, AB
Valve AB has flow rate=0; tunnels lead to valves BD, QX
Valve QP has flow rate=0; tunnels lead to valves AD, EZ
Valve OF has flow rate=0; tunnels lead to valves DX, CW
Valve AA has flow rate=0; tunnels lead to valves QL, RZ, SO, MM, HW
Valve RQ has flow rate=0; tunnels lead to valves GL, QG
Valve ZL has flow rate=0; tunnels lead to valves NS, FD
Valve KH has flow rate=0; tunnels lead to valves GT, QW
Valve JR has flow rate=0; tunnels lead to valves FG, PH
Valve PH has flow rate=0; tunnels lead to valves CW, JR
Valve LC has flow rate=0; tunnels lead to valves VQ, SG
Valve FD has flow rate=20; tunnels lead to valves LN, QA, ZL
Valve NZ has flow rate=15; tunnels lead to valves UZ, JX
Valve ML has flow rate=22; tunnels lead to valves OW, PQ, NO
Valve PF has flow rate=0; tunnels lead to valves QW, CH
Valve UP has flow rate=19; tunnels lead to valves RY, CV, EZ
Valve VM has flow rate=0; tunnels lead to valves RY, CH
Valve DX has flow rate=3; tunnels lead to valves BO, QL, BP, OF, QG
Valve QL has flow rate=0; tunnels lead to valves AA, DX
Valve HW has flow rate=0; tunnels lead to valves UY, AA
Valve GL has flow rate=8; tunnels lead to valves YK, RQ
Valve QG has flow rate=0; tunnels lead to valves DX, RQ
Valve IN has flow rate=0; tunnels lead to valves FG, BO
Valve NO has flow rate=0; tunnels lead to valves SG, ML
Valve SO has flow rate=0; tunnels lead to valves FG, AA
Valve RY has flow rate=0; tunnels lead to valves UP, VM
Valve CH has flow rate=13; tunnels lead to valves GN, VM, PF, ZO
Valve AD has flow rate=17; tunnel leads to valve QP
Valve TI has flow rate=0; tunnels lead to valves BP, QW
Valve UY has flow rate=0; tunnels lead to valves HW, QW
Valve AT has flow rate=24; tunnels lead to valves OW, CO
Valve GT has flow rate=0; tunnels lead to valves CW, KH
Valve ZO has flow rate=0; tunnels lead to valves RZ, CH
Valve QX has flow rate=0; tunnels lead to valves AB, SG
Valve BO has flow rate=0; tunnels lead to valves IN, DX
Valve OW has flow rate=0; tunnels lead to valves AT, ML

10
res/16/test-input.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

31
src/days/d16.rs Normal file
View file

@ -0,0 +1,31 @@
use std::fs;
use std::collections::HashMap;
pub fn solve() {
let path = "res/16/input.txt";
let contents = fs::read_to_string(path).expect("File read error");
let mut valves = HashMap::<String, (i32, Vec::<String>)>::new();
contents
.lines()
.filter(|line| *line != "")
.for_each(|line| {
let (valve, conn_valves) = line.split_at(line.find(";").unwrap());
let conn_valves = conn_valves
.replace("; tunnels lead to valve", "")
.replace("s", "")
.replace(" ", "");
let conn_valves: Vec<&str> = conn_valves.split(",").collect();
let conn_valves: Vec<String> = conn_valves.iter().map(|c| c.to_string()).collect();
let valve: Vec<&str> = valve.split_whitespace().collect();
let flow_rate = valve[4].replace("rate=", "").parse::<i32>().unwrap();
let valve = valve[1].to_string();
valves.insert(valve, (flow_rate, conn_valves));
});
dbg!(valves);
}

View file

@ -1,7 +1,7 @@
pub mod days; pub mod days;
fn main() { fn main() {
days::d15::solve() days::d16::solve()
//_all_days() //_all_days()
} }