Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 16 - Proboscidea Volcanium 🌋 #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/Day-16.yml
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions src/day_16.data
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions src/day_16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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");

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::<usize>().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());

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)
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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."),
};
}