From 4e535dfdb69a2c4ed9a49d2feb17dbabccf69500 Mon Sep 17 00:00:00 2001 From: Jonathan Flueren Date: Fri, 16 Dec 2022 12:18:42 +0100 Subject: [PATCH] Day 16 - init & parsing --- res/16/input.txt | 58 +++++++++++++++++++++++++++++++++++++++++++ res/16/test-input.txt | 10 ++++++++ src/days/d16.rs | 31 +++++++++++++++++++++++ src/main.rs | 2 +- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 res/16/input.txt create mode 100644 res/16/test-input.txt create mode 100644 src/days/d16.rs diff --git a/res/16/input.txt b/res/16/input.txt new file mode 100644 index 0000000..6c330b9 --- /dev/null +++ b/res/16/input.txt @@ -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 diff --git a/res/16/test-input.txt b/res/16/test-input.txt new file mode 100644 index 0000000..85fa5b0 --- /dev/null +++ b/res/16/test-input.txt @@ -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 \ No newline at end of file diff --git a/src/days/d16.rs b/src/days/d16.rs new file mode 100644 index 0000000..e6aea09 --- /dev/null +++ b/src/days/d16.rs @@ -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::)>::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 = 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::().unwrap(); + let valve = valve[1].to_string(); + + valves.insert(valve, (flow_rate, conn_valves)); + }); + + dbg!(valves); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7910a3f..9cb9d32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ pub mod days; fn main() { - days::d15::solve() + days::d16::solve() //_all_days() }