From f1481faa02ef73bd80b369bbe2cf8fc2e15c8383 Mon Sep 17 00:00:00 2001 From: Leif Gehrmann Date: Sat, 17 Dec 2022 17:53:56 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Day=2016=20-=20Proboscidea=20Volcanium=20?= =?UTF-8?q?=F0=9F=8C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Day-16.yml | 18 +++++++++++ src/day_16.data | 59 ++++++++++++++++++++++++++++++++++++ src/day_16.rs | 5 +++ 3 files changed, 82 insertions(+) create mode 100644 .github/workflows/Day-16.yml create mode 100644 src/day_16.data create mode 100644 src/day_16.rs diff --git a/.github/workflows/Day-16.yml b/.github/workflows/Day-16.yml new file mode 100644 index 0000000..8033697 --- /dev/null +++ b/.github/workflows/Day-16.yml @@ -0,0 +1,18 @@ +name: Day-16 + +on: + workflow_dispatch: + push: + paths: + - '**16*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --release --verbose + - name: Run + run: time target/release/aoc 16 diff --git a/src/day_16.data b/src/day_16.data new file mode 100644 index 0000000..78feeee --- /dev/null +++ b/src/day_16.data @@ -0,0 +1,59 @@ +Valve SY has flow rate=0; tunnels lead to valves GW, LW +Valve TS has flow rate=0; tunnels lead to valves CC, OP +Valve LU has flow rate=0; tunnels lead to valves PS, XJ +Valve ND has flow rate=0; tunnels lead to valves EN, TL +Valve PD has flow rate=0; tunnels lead to valves TL, LI +Valve VF has flow rate=0; tunnels lead to valves LW, RX +Valve LD has flow rate=0; tunnels lead to valves AD, LP +Valve DG has flow rate=0; tunnels lead to valves DR, SS +Valve IG has flow rate=8; tunnels lead to valves AN, YA, GA +Valve LK has flow rate=0; tunnels lead to valves HQ, LW +Valve TD has flow rate=14; tunnels lead to valves BG, CQ +Valve CQ has flow rate=0; tunnels lead to valves TD, HD +Valve AZ has flow rate=0; tunnels lead to valves AD, XW +Valve ZU has flow rate=0; tunnels lead to valves TL, AN +Valve HD has flow rate=0; tunnels lead to valves BP, CQ +Valve FX has flow rate=0; tunnels lead to valves LW, XM +Valve CU has flow rate=18; tunnels lead to valves BX, VA, RX, DF +Valve SS has flow rate=17; tunnels lead to valves DG, ZD, ZG +Valve BP has flow rate=19; tunnels lead to valves HD, ZD +Valve DZ has flow rate=0; tunnels lead to valves XS, CC +Valve PS has flow rate=0; tunnels lead to valves GH, LU +Valve TA has flow rate=0; tunnels lead to valves LI, AA +Valve BG has flow rate=0; tunnels lead to valves TD, ZG +Valve WP has flow rate=0; tunnels lead to valves OB, AA +Valve XS has flow rate=9; tunnels lead to valves EN, DZ +Valve AA has flow rate=0; tunnels lead to valves WG, GA, VO, WP, TA +Valve LW has flow rate=25; tunnels lead to valves LK, FX, SY, VF +Valve AD has flow rate=23; tunnels lead to valves DF, GW, AZ, LD, FM +Valve EN has flow rate=0; tunnels lead to valves ND, XS +Valve ZG has flow rate=0; tunnels lead to valves SS, BG +Valve LI has flow rate=11; tunnels lead to valves YA, XM, TA, PD +Valve VO has flow rate=0; tunnels lead to valves AA, OD +Valve AN has flow rate=0; tunnels lead to valves IG, ZU +Valve GH has flow rate=15; tunnels lead to valves VA, PS +Valve OP has flow rate=4; tunnels lead to valves AJ, TS, FM, BX, NM +Valve BX has flow rate=0; tunnels lead to valves OP, CU +Valve RX has flow rate=0; tunnels lead to valves CU, VF +Valve FM has flow rate=0; tunnels lead to valves OP, AD +Valve OB has flow rate=0; tunnels lead to valves WP, XW +Valve CC has flow rate=3; tunnels lead to valves QS, LP, DZ, OD, TS +Valve LP has flow rate=0; tunnels lead to valves LD, CC +Valve NM has flow rate=0; tunnels lead to valves WH, OP +Valve HQ has flow rate=0; tunnels lead to valves XW, LK +Valve GW has flow rate=0; tunnels lead to valves SY, AD +Valve QS has flow rate=0; tunnels lead to valves CC, XW +Valve DF has flow rate=0; tunnels lead to valves AD, CU +Valve XM has flow rate=0; tunnels lead to valves LI, FX +Valve VA has flow rate=0; tunnels lead to valves CU, GH +Valve GA has flow rate=0; tunnels lead to valves IG, AA +Valve YA has flow rate=0; tunnels lead to valves LI, IG +Valve XW has flow rate=20; tunnels lead to valves OB, HQ, QS, WH, AZ +Valve XJ has flow rate=24; tunnel leads to valve LU +Valve AJ has flow rate=0; tunnels lead to valves WG, OP +Valve WH has flow rate=0; tunnels lead to valves XW, NM +Valve TL has flow rate=13; tunnels lead to valves PD, DR, ZU, ND +Valve OD has flow rate=0; tunnels lead to valves CC, VO +Valve ZD has flow rate=0; tunnels lead to valves SS, BP +Valve DR has flow rate=0; tunnels lead to valves DG, TL +Valve WG has flow rate=0; tunnels lead to valves AJ, AA \ No newline at end of file diff --git a/src/day_16.rs b/src/day_16.rs new file mode 100644 index 0000000..0ff10ce --- /dev/null +++ b/src/day_16.rs @@ -0,0 +1,5 @@ +use crate::input_reader; + +pub fn run() { + let input = input_reader::read_file_in_cwd("src/day_16.data"); +} From c87c0cdc12a77797d74b09662240d03432f41a93 Mon Sep 17 00:00:00 2001 From: Leif Gehrmann Date: Sat, 24 Dec 2022 12:06:23 +0100 Subject: [PATCH 2/3] Parsed data --- src/day_16.rs | 18 ++++++++++++++++++ src/main.rs | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/day_16.rs b/src/day_16.rs index 0ff10ce..b9e00cf 100644 --- a/src/day_16.rs +++ b/src/day_16.rs @@ -1,5 +1,23 @@ use crate::input_reader; +use std::collections::HashMap; +use regex::Regex; pub fn run() { let input = input_reader::read_file_in_cwd("src/day_16.data"); + + let mut valves_flow: HashMap<&str, usize> = HashMap::new(); + let mut valves_tunnels: HashMap<&str, Vec<&str>> = HashMap::new(); + + let re = Regex::new(r"Valve ([A-Z]+) has flow rate=([0-9]+); tunnels lead to valves ([A-Z, ]+)").unwrap(); + let valves_str: Vec<&str> = input.split("\n").collect(); + valves_str.iter().for_each(|&valve_str| { + let caps = re.captures(valve_str).unwrap(); + let valve = caps.get(1).map_or("", |m| m.as_str()); + let valve_flow = caps.get(2).map_or("0", |m| m.as_str()).parse::().unwrap(); + let valve_tunnels_str = caps.get(3).map_or("", |m| m.as_str()); + let valve_tunnels: Vec<&str> = valve_tunnels_str.split(", ").collect(); + + valves_flow.insert(valve, valve_flow); + valves_tunnels.insert(valve, valve_tunnels.clone()); + }); } diff --git a/src/main.rs b/src/main.rs index 80e4654..154e86d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ mod day_12; mod day_13; mod day_14; mod day_15; +mod day_16; fn main() { let day: String = std::env::args().nth(1).expect( @@ -37,6 +38,7 @@ fn main() { "13" => day_13::run(), "14" => day_14::run(), "15" => day_15::run(), + "16" => day_16::run(), _ => println!("No valid day given. Possible options are: 01-25."), }; } From 64326ffab5d74a5796f6ca850e8a6a9f49f6192e Mon Sep 17 00:00:00 2001 From: Leif Gehrmann Date: Sun, 25 Dec 2022 18:04:28 +0100 Subject: [PATCH 3/3] Print data into a graph for visualization --- src/day_16.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/day_16.rs b/src/day_16.rs index b9e00cf..51aecd2 100644 --- a/src/day_16.rs +++ b/src/day_16.rs @@ -2,6 +2,25 @@ use crate::input_reader; use std::collections::HashMap; use regex::Regex; +pub fn part1( + valves_flow: HashMap<&str, usize>, + valves_tunnels: HashMap<&str, Vec<&str>>, + start: &str, + minutes: usize +) { + // Reduce the problem by calculating the costs between each valve that + // has a non-zero flow value. + + // Calculate the cost from the `start` valve to all other valves. + + // We're gonna assume that we want to visit valves with the highest flow + // first, and visit the valves with less flow last. So we compute an array + // of valves sorted by flow. + + // Create combinations of solutions. + +} + pub fn run() { let input = input_reader::read_file_in_cwd("src/day_16.data"); @@ -19,5 +38,17 @@ pub fn run() { valves_flow.insert(valve, valve_flow); valves_tunnels.insert(valve, valve_tunnels.clone()); + + if valve_flow != 0 { + println!(" {}[{} flow={}]", valve, valve, valve_flow); + } + for valve_tunnel in valve_tunnels.clone() { + println!(" {} --> {}", valve, valve_tunnel); + } }); + + let start = "AA"; + let minutes = 30; + + part1(valves_flow, valves_tunnels, start, minutes) }