Solutions for 2022, as well as 2015-2018 and 2019 up to day 11
This commit is contained in:
commit
1895197c49
722 changed files with 375457 additions and 0 deletions
7
2022/day16-proboscidae_volcanium/Cargo.toml
Normal file
7
2022/day16-proboscidae_volcanium/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "day16-proboscidae_volcanium"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
223
2022/day16-proboscidae_volcanium/challenge.md
Normal file
223
2022/day16-proboscidae_volcanium/challenge.md
Normal file
|
@ -0,0 +1,223 @@
|
|||
--- Day 16: Proboscidea Volcanium ---
|
||||
|
||||
The sensors have led you to the origin of the distress signal: yet another handheld device, just like the one the Elves gave you. However, you don't see any Elves around; instead, the device is surrounded by elephants! They must have gotten lost in these tunnels, and one of the elephants apparently figured out how to turn on the distress signal.
|
||||
|
||||
The ground rumbles again, much stronger this time. What kind of cave is this, exactly? You scan the cave with your handheld device; it reports mostly igneous rock, some ash, pockets of pressurized gas, magma... this isn't just a cave, it's a volcano!
|
||||
|
||||
You need to get the elephants out of here, quickly. Your device estimates that you have 30 minutes before the volcano erupts, so you don't have time to go back out the way you came in.
|
||||
|
||||
You scan the cave for other options and discover a network of pipes and pressure-release valves. You aren't sure how such a system got into a volcano, but you don't have time to complain; your device produces a report (your puzzle input) of each valve's flow rate if it were opened (in pressure per minute) and the tunnels you could use to move between the valves.
|
||||
|
||||
There's even a valve in the room you and the elephants are currently standing in labeled AA. You estimate it will take you one minute to open a single valve and one minute to follow any tunnel from one valve to another. What is the most pressure you could release?
|
||||
|
||||
For example, suppose you had the following scan output:
|
||||
|
||||
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
|
||||
All of the valves begin closed. You start at valve AA, but it must be damaged or jammed or something: its flow rate is 0, so there's no point in opening it. However, you could spend one minute moving to valve BB and another minute opening it; doing so would release pressure during the remaining 28 minutes at a flow rate of 13, a total eventual pressure release of 28 * 13 = 364. Then, you could spend your third minute moving to valve CC and your fourth minute opening it, providing an additional 26 minutes of eventual pressure release at a flow rate of 2, or 52 total pressure released by valve CC.
|
||||
|
||||
Making your way through the tunnels like this, you could probably open many or all of the valves by the time 30 minutes have elapsed. However, you need to release as much pressure as possible, so you'll need to be methodical. Instead, consider this approach:
|
||||
|
||||
== Minute 1 ==
|
||||
No valves are open.
|
||||
You move to valve DD.
|
||||
|
||||
== Minute 2 ==
|
||||
No valves are open.
|
||||
You open valve DD.
|
||||
|
||||
== Minute 3 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You move to valve CC.
|
||||
|
||||
== Minute 4 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You move to valve BB.
|
||||
|
||||
== Minute 5 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You open valve BB.
|
||||
|
||||
== Minute 6 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You move to valve AA.
|
||||
|
||||
== Minute 7 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You move to valve II.
|
||||
|
||||
== Minute 8 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You move to valve JJ.
|
||||
|
||||
== Minute 9 ==
|
||||
Valves BB and DD are open, releasing 33 pressure.
|
||||
You open valve JJ.
|
||||
|
||||
== Minute 10 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve II.
|
||||
|
||||
== Minute 11 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve AA.
|
||||
|
||||
== Minute 12 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve DD.
|
||||
|
||||
== Minute 13 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve EE.
|
||||
|
||||
== Minute 14 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve FF.
|
||||
|
||||
== Minute 15 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve GG.
|
||||
|
||||
== Minute 16 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You move to valve HH.
|
||||
|
||||
== Minute 17 ==
|
||||
Valves BB, DD, and JJ are open, releasing 54 pressure.
|
||||
You open valve HH.
|
||||
|
||||
== Minute 18 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve GG.
|
||||
|
||||
== Minute 19 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve FF.
|
||||
|
||||
== Minute 20 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve EE.
|
||||
|
||||
== Minute 21 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You open valve EE.
|
||||
|
||||
== Minute 22 ==
|
||||
Valves BB, DD, EE, HH, and JJ are open, releasing 79 pressure.
|
||||
You move to valve DD.
|
||||
|
||||
== Minute 23 ==
|
||||
Valves BB, DD, EE, HH, and JJ are open, releasing 79 pressure.
|
||||
You move to valve CC.
|
||||
|
||||
== Minute 24 ==
|
||||
Valves BB, DD, EE, HH, and JJ are open, releasing 79 pressure.
|
||||
You open valve CC.
|
||||
|
||||
== Minute 25 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 26 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 27 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 28 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 29 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
== Minute 30 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
This approach lets you release the most pressure possible in 30 minutes with this valve layout, 1651.
|
||||
|
||||
Work out the steps to release the most pressure in 30 minutes. What is the most pressure you can release?
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
You're worried that even with an optimal approach, the pressure released won't be enough. What if you got one of the elephants to help you?
|
||||
|
||||
It would take you 4 minutes to teach an elephant how to open the right valves in the right order, leaving you with only 26 minutes to actually execute your plan. Would having two of you working together be better, even if it means having less time? (Assume that you teach the elephant before opening any valves yourself, giving you both the same full 26 minutes.)
|
||||
|
||||
In the example above, you could teach the elephant to help you as follows:
|
||||
|
||||
== Minute 1 ==
|
||||
No valves are open.
|
||||
You move to valve II.
|
||||
The elephant moves to valve DD.
|
||||
|
||||
== Minute 2 ==
|
||||
No valves are open.
|
||||
You move to valve JJ.
|
||||
The elephant opens valve DD.
|
||||
|
||||
== Minute 3 ==
|
||||
Valve DD is open, releasing 20 pressure.
|
||||
You open valve JJ.
|
||||
The elephant moves to valve EE.
|
||||
|
||||
== Minute 4 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You move to valve II.
|
||||
The elephant moves to valve FF.
|
||||
|
||||
== Minute 5 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You move to valve AA.
|
||||
The elephant moves to valve GG.
|
||||
|
||||
== Minute 6 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You move to valve BB.
|
||||
The elephant moves to valve HH.
|
||||
|
||||
== Minute 7 ==
|
||||
Valves DD and JJ are open, releasing 41 pressure.
|
||||
You open valve BB.
|
||||
The elephant opens valve HH.
|
||||
|
||||
== Minute 8 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You move to valve CC.
|
||||
The elephant moves to valve GG.
|
||||
|
||||
== Minute 9 ==
|
||||
Valves BB, DD, HH, and JJ are open, releasing 76 pressure.
|
||||
You open valve CC.
|
||||
The elephant moves to valve FF.
|
||||
|
||||
== Minute 10 ==
|
||||
Valves BB, CC, DD, HH, and JJ are open, releasing 78 pressure.
|
||||
The elephant moves to valve EE.
|
||||
|
||||
== Minute 11 ==
|
||||
Valves BB, CC, DD, HH, and JJ are open, releasing 78 pressure.
|
||||
The elephant opens valve EE.
|
||||
|
||||
(At this point, all valves are open.)
|
||||
|
||||
== Minute 12 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
...
|
||||
|
||||
== Minute 20 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
|
||||
...
|
||||
|
||||
== Minute 26 ==
|
||||
Valves BB, CC, DD, EE, HH, and JJ are open, releasing 81 pressure.
|
||||
With the elephant helping, after 26 minutes, the best you could do would release a total of 1707 pressure.
|
||||
|
||||
With you and an elephant working together for 26 minutes, what is the most pressure you could release?
|
52
2022/day16-proboscidae_volcanium/input
Normal file
52
2022/day16-proboscidae_volcanium/input
Normal file
|
@ -0,0 +1,52 @@
|
|||
Valve JZ has flow rate=0; tunnels lead to valves IR, LY
|
||||
Valve KD has flow rate=0; tunnels lead to valves NJ, ZS
|
||||
Valve VW has flow rate=0; tunnels lead to valves IT, VH
|
||||
Valve HS has flow rate=0; tunnels lead to valves OC, PN
|
||||
Valve EU has flow rate=19; tunnel leads to valve GQ
|
||||
Valve XF has flow rate=0; tunnels lead to valves WL, QD
|
||||
Valve DD has flow rate=8; tunnels lead to valves GQ, YY, JV, SK
|
||||
Valve TA has flow rate=0; tunnels lead to valves NJ, VJ
|
||||
Valve IR has flow rate=9; tunnels lead to valves JZ, WI, VJ, GC, WG
|
||||
Valve SS has flow rate=17; tunnels lead to valves SI, IZ, RK, WI
|
||||
Valve SG has flow rate=0; tunnels lead to valves NV, NJ
|
||||
Valve IT has flow rate=0; tunnels lead to valves LL, VW
|
||||
Valve CP has flow rate=24; tunnels lead to valves HN, ZK, EJ
|
||||
Valve SK has flow rate=0; tunnels lead to valves LL, DD
|
||||
Valve IS has flow rate=0; tunnels lead to valves AA, LL
|
||||
Valve HN has flow rate=0; tunnels lead to valves FF, CP
|
||||
Valve VH has flow rate=10; tunnels lead to valves QO, VW, RV, PN
|
||||
Valve JV has flow rate=0; tunnels lead to valves DD, RK
|
||||
Valve ZS has flow rate=0; tunnels lead to valves KD, LL
|
||||
Valve UC has flow rate=25; tunnels lead to valves JD, IV
|
||||
Valve WI has flow rate=0; tunnels lead to valves SS, IR
|
||||
Valve UR has flow rate=0; tunnels lead to valves QD, LY
|
||||
Valve GC has flow rate=0; tunnels lead to valves AA, IR
|
||||
Valve YY has flow rate=0; tunnels lead to valves DD, AA
|
||||
Valve IV has flow rate=0; tunnels lead to valves ZK, UC
|
||||
Valve BM has flow rate=0; tunnels lead to valves SA, WL
|
||||
Valve JD has flow rate=0; tunnels lead to valves IZ, UC
|
||||
Valve WL has flow rate=12; tunnels lead to valves EF, BM, EJ, XF
|
||||
Valve AA has flow rate=0; tunnels lead to valves NV, YY, GC, IS, QO
|
||||
Valve WG has flow rate=0; tunnels lead to valves LL, IR
|
||||
Valve GQ has flow rate=0; tunnels lead to valves EU, DD
|
||||
Valve SI has flow rate=0; tunnels lead to valves SS, NJ
|
||||
Valve KH has flow rate=13; tunnels lead to valves SA, ON
|
||||
Valve PC has flow rate=22; tunnel leads to valve ON
|
||||
Valve QD has flow rate=14; tunnels lead to valves XF, UR
|
||||
Valve IZ has flow rate=0; tunnels lead to valves SS, JD
|
||||
Valve QO has flow rate=0; tunnels lead to valves AA, VH
|
||||
Valve SA has flow rate=0; tunnels lead to valves BM, KH
|
||||
Valve NV has flow rate=0; tunnels lead to valves AA, SG
|
||||
Valve ZK has flow rate=0; tunnels lead to valves CP, IV
|
||||
Valve ON has flow rate=0; tunnels lead to valves PC, KH
|
||||
Valve PN has flow rate=0; tunnels lead to valves HS, VH
|
||||
Valve RV has flow rate=0; tunnels lead to valves NJ, VH
|
||||
Valve RK has flow rate=0; tunnels lead to valves SS, JV
|
||||
Valve OC has flow rate=18; tunnel leads to valve HS
|
||||
Valve EF has flow rate=0; tunnels lead to valves LY, WL
|
||||
Valve VJ has flow rate=0; tunnels lead to valves TA, IR
|
||||
Valve LL has flow rate=5; tunnels lead to valves ZS, IT, SK, IS, WG
|
||||
Valve FF has flow rate=0; tunnels lead to valves HN, LY
|
||||
Valve LY has flow rate=21; tunnels lead to valves EF, FF, UR, JZ
|
||||
Valve EJ has flow rate=0; tunnels lead to valves WL, CP
|
||||
Valve NJ has flow rate=6; tunnels lead to valves RV, KD, SG, SI, TA
|
224
2022/day16-proboscidae_volcanium/src/main.rs
Normal file
224
2022/day16-proboscidae_volcanium/src/main.rs
Normal file
|
@ -0,0 +1,224 @@
|
|||
use std::{fs, usize, collections::HashMap};
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Valve {
|
||||
id: u8,
|
||||
flow_rate: usize,
|
||||
connected_valves: Vec<u8>,
|
||||
open: bool,
|
||||
}
|
||||
|
||||
fn get_all_distances(valves: &[Valve]) -> HashMap<(u8, u8), u8> {
|
||||
let mut network: HashMap<(u8, u8), u8> = valves.iter()
|
||||
.flat_map(|origin| origin.connected_valves.iter()
|
||||
.map(|destination| ((origin.id, *destination),1_u8)))
|
||||
.collect();
|
||||
|
||||
for _ in 0..3 {
|
||||
for a in valves {
|
||||
for b in valves {
|
||||
for c in valves {
|
||||
if let Some(ab) = network.get(&(a.id, b.id)) {
|
||||
if let Some(bc) = network.get(&(b.id, c.id)) {
|
||||
let ac = network.get(&(a.id, c.id));
|
||||
network.insert((a.id, c.id), (ab+bc).min(*ac.unwrap_or(&u8::MAX)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
network
|
||||
}
|
||||
|
||||
fn lookup_or_insert<'a>(array: &mut Vec<&'a str>, value: &'a str) -> u8 {
|
||||
if let Some(index) = array.iter().position(|val| val==&value) {
|
||||
index as u8
|
||||
} else {
|
||||
array.push(value);
|
||||
(array.len()-1) as u8
|
||||
}
|
||||
}
|
||||
|
||||
fn read_file(path: &str) -> String {
|
||||
fs::read_to_string(path)
|
||||
.expect("File not Found")
|
||||
}
|
||||
|
||||
fn try_permutations(valves: &[Valve], distances: &HashMap<(u8,u8),u8>, starting_index: u8, time: u8) -> usize {
|
||||
let closed_valves: Vec<Valve> = valves.iter().filter(|v| !v.open).cloned().collect();
|
||||
let mut permutations_map: Vec<Vec<Vec<usize>>> = vec![(0..closed_valves.len()).map(|i| vec![closed_valves[i].id as usize]).collect()];
|
||||
|
||||
for _step in 0..closed_valves.len() {
|
||||
let mut new_permutations = Vec::new();
|
||||
for permutation in &permutations_map[permutations_map.len()-1] {
|
||||
for valve in &closed_valves {
|
||||
let valve_id = valve.id as usize;
|
||||
if permutation.contains(&valve_id) {
|
||||
continue;
|
||||
}
|
||||
let mut new_permutation = permutation.clone();
|
||||
new_permutation.push(valve_id);
|
||||
let mut last_position = starting_index as usize;
|
||||
let mut time_spent = 0;
|
||||
for position in &new_permutation {
|
||||
time_spent += distances.get(&(last_position as u8, *position as u8)).unwrap() + 1;
|
||||
last_position = *position;
|
||||
}
|
||||
if time_spent < time {
|
||||
new_permutations.push(new_permutation);
|
||||
}
|
||||
}
|
||||
}
|
||||
permutations_map.push(new_permutations.clone());
|
||||
}
|
||||
|
||||
let mut available_permutations: Vec<Vec<usize>> = Vec::new();
|
||||
for level in permutations_map {
|
||||
for permutation in level {
|
||||
available_permutations.push(permutation.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut best_so_far = 0;
|
||||
// try all non-overlapping permutations
|
||||
for human_permutation in &available_permutations {
|
||||
let this_try = try_permutation(valves, distances, human_permutation, starting_index, time);
|
||||
if this_try > best_so_far {
|
||||
best_so_far = this_try;
|
||||
}
|
||||
}
|
||||
best_so_far
|
||||
}
|
||||
|
||||
fn try_permutations_with_elephants(valves: &[Valve], distances: &HashMap<(u8,u8),u8>, starting_index: u8, time: u8) -> usize {
|
||||
let closed_valves: Vec<Valve> = valves.iter().filter(|v| !v.open).cloned().collect();
|
||||
let mut permutations_map: Vec<Vec<Vec<usize>>> = vec![(0..closed_valves.len()).map(|i| vec![closed_valves[i].id as usize]).collect()];
|
||||
|
||||
for _step in 0..closed_valves.len() {
|
||||
let mut new_permutations = Vec::new();
|
||||
for permutation in &permutations_map[permutations_map.len()-1] {
|
||||
for valve in &closed_valves {
|
||||
let valve_id = valve.id as usize;
|
||||
if permutation.contains(&valve_id) {
|
||||
continue;
|
||||
}
|
||||
let mut new_permutation = permutation.clone();
|
||||
new_permutation.push(valve_id);
|
||||
let mut last_position = starting_index as usize;
|
||||
let mut time_spent = 0;
|
||||
for position in &new_permutation {
|
||||
time_spent += distances.get(&(last_position as u8, *position as u8)).unwrap() + 1;
|
||||
last_position = *position;
|
||||
}
|
||||
if time_spent < time {
|
||||
new_permutations.push(new_permutation);
|
||||
}
|
||||
}
|
||||
}
|
||||
permutations_map.push(new_permutations.clone());
|
||||
}
|
||||
|
||||
let mut available_permutations: Vec<Vec<usize>> = Vec::new();
|
||||
for level in permutations_map {
|
||||
for permutation in level {
|
||||
available_permutations.push(permutation.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut best_so_far = 0;
|
||||
// try all non-overlapping permutations
|
||||
for human_permutation in &available_permutations {
|
||||
'next_permutation: for elephant_permutation in &available_permutations {
|
||||
// make sure we don't get the same permutation with reversed roles
|
||||
if human_permutation[0] < elephant_permutation[0] {
|
||||
continue;
|
||||
}
|
||||
for valve in elephant_permutation {
|
||||
if human_permutation.contains(valve) {
|
||||
continue 'next_permutation;
|
||||
}
|
||||
}
|
||||
let this_try = try_permutation(valves, distances, human_permutation, starting_index, time) + try_permutation(valves, distances, elephant_permutation, starting_index, time);
|
||||
if this_try > best_so_far {
|
||||
best_so_far = this_try;
|
||||
}
|
||||
}
|
||||
}
|
||||
best_so_far
|
||||
}
|
||||
|
||||
fn try_permutation(valves: &[Valve], distances: &HashMap<(u8, u8), u8>, permutation: &[usize], starting_index: u8, time: u8) -> usize {
|
||||
let mut last_position = starting_index as usize;
|
||||
let mut time_remaining = time as usize;
|
||||
let mut released = 0;
|
||||
for valve_id in permutation {
|
||||
time_remaining -= *distances.get(&(last_position as u8, *valve_id as u8)).unwrap() as usize + 1;
|
||||
released += time_remaining * valves[*valve_id].flow_rate as usize;
|
||||
last_position = *valve_id;
|
||||
}
|
||||
released
|
||||
}
|
||||
|
||||
fn init(scan: &str) -> (Vec<Valve>, HashMap<(u8, u8), u8>, u8) {
|
||||
let mut ids = Vec::new();
|
||||
let mut all_valves: Vec<Valve> = scan.lines()
|
||||
.map(|valve_line| {
|
||||
let components = valve_line.split(' ').collect::<Vec<&str>>();
|
||||
if components.len() < 10 { panic!("{valve_line} has fewer than 10 components."); }
|
||||
let id = lookup_or_insert(&mut ids, components[1]);
|
||||
let flow_rate_with_semicolon = &components[4][5..];
|
||||
let flow_rate = flow_rate_with_semicolon[..flow_rate_with_semicolon.len()-1].parse::<usize>().unwrap();
|
||||
let mut connected_valves = Vec::new();
|
||||
for other_valve_with_comma in components.iter().skip(9).take(components.len()-10) {
|
||||
connected_valves.push(lookup_or_insert(&mut ids, &other_valve_with_comma[..other_valve_with_comma.len()-1]));
|
||||
}
|
||||
connected_valves.push(lookup_or_insert(&mut ids, components[components.len()-1]));
|
||||
|
||||
Valve {
|
||||
id,
|
||||
flow_rate,
|
||||
connected_valves,
|
||||
open: flow_rate == 0,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
all_valves.sort_by_key(|v| v.id);
|
||||
let all_distances = get_all_distances(&all_valves);
|
||||
|
||||
(all_valves, all_distances, lookup_or_insert(&mut ids, "AA"))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//let scan = read_file("sample_input");
|
||||
let scan = read_file("input");
|
||||
|
||||
|
||||
let (all_valves, all_distances, starting_index) = init(&scan);
|
||||
//let all_distances = get_all_distances(&all_valves);
|
||||
//let starting_index = lookup_or_insert(&mut ids, "AA");
|
||||
|
||||
println!("Working alone, we release {} units.", try_permutations(&all_valves, &all_distances, starting_index, 30));
|
||||
|
||||
let with_elephants = try_permutations_with_elephants(&all_valves, &all_distances, starting_index, 26);
|
||||
println!("Using elephants, we release {with_elephants} units.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_input() {
|
||||
let scan = read_file("tests/sample_input");
|
||||
let (all_valves, all_distances, starting_index) = init(&scan);
|
||||
|
||||
assert_eq!(try_permutations(&all_valves, &all_distances, starting_index, 30), 1651);
|
||||
assert_eq!(try_permutations_with_elephants(&all_valves, &all_distances, starting_index, 26), 1707);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn challenge_input() {
|
||||
let scan = read_file("tests/input");
|
||||
let (all_valves, all_distances, starting_index) = init(&scan);
|
||||
|
||||
assert_eq!(try_permutations(&all_valves, &all_distances, starting_index, 30), 2056);
|
||||
assert_eq!(try_permutations_with_elephants(&all_valves, &all_distances, starting_index, 26), 2513);
|
||||
}
|
52
2022/day16-proboscidae_volcanium/tests/input
Normal file
52
2022/day16-proboscidae_volcanium/tests/input
Normal file
|
@ -0,0 +1,52 @@
|
|||
Valve JZ has flow rate=0; tunnels lead to valves IR, LY
|
||||
Valve KD has flow rate=0; tunnels lead to valves NJ, ZS
|
||||
Valve VW has flow rate=0; tunnels lead to valves IT, VH
|
||||
Valve HS has flow rate=0; tunnels lead to valves OC, PN
|
||||
Valve EU has flow rate=19; tunnel leads to valve GQ
|
||||
Valve XF has flow rate=0; tunnels lead to valves WL, QD
|
||||
Valve DD has flow rate=8; tunnels lead to valves GQ, YY, JV, SK
|
||||
Valve TA has flow rate=0; tunnels lead to valves NJ, VJ
|
||||
Valve IR has flow rate=9; tunnels lead to valves JZ, WI, VJ, GC, WG
|
||||
Valve SS has flow rate=17; tunnels lead to valves SI, IZ, RK, WI
|
||||
Valve SG has flow rate=0; tunnels lead to valves NV, NJ
|
||||
Valve IT has flow rate=0; tunnels lead to valves LL, VW
|
||||
Valve CP has flow rate=24; tunnels lead to valves HN, ZK, EJ
|
||||
Valve SK has flow rate=0; tunnels lead to valves LL, DD
|
||||
Valve IS has flow rate=0; tunnels lead to valves AA, LL
|
||||
Valve HN has flow rate=0; tunnels lead to valves FF, CP
|
||||
Valve VH has flow rate=10; tunnels lead to valves QO, VW, RV, PN
|
||||
Valve JV has flow rate=0; tunnels lead to valves DD, RK
|
||||
Valve ZS has flow rate=0; tunnels lead to valves KD, LL
|
||||
Valve UC has flow rate=25; tunnels lead to valves JD, IV
|
||||
Valve WI has flow rate=0; tunnels lead to valves SS, IR
|
||||
Valve UR has flow rate=0; tunnels lead to valves QD, LY
|
||||
Valve GC has flow rate=0; tunnels lead to valves AA, IR
|
||||
Valve YY has flow rate=0; tunnels lead to valves DD, AA
|
||||
Valve IV has flow rate=0; tunnels lead to valves ZK, UC
|
||||
Valve BM has flow rate=0; tunnels lead to valves SA, WL
|
||||
Valve JD has flow rate=0; tunnels lead to valves IZ, UC
|
||||
Valve WL has flow rate=12; tunnels lead to valves EF, BM, EJ, XF
|
||||
Valve AA has flow rate=0; tunnels lead to valves NV, YY, GC, IS, QO
|
||||
Valve WG has flow rate=0; tunnels lead to valves LL, IR
|
||||
Valve GQ has flow rate=0; tunnels lead to valves EU, DD
|
||||
Valve SI has flow rate=0; tunnels lead to valves SS, NJ
|
||||
Valve KH has flow rate=13; tunnels lead to valves SA, ON
|
||||
Valve PC has flow rate=22; tunnel leads to valve ON
|
||||
Valve QD has flow rate=14; tunnels lead to valves XF, UR
|
||||
Valve IZ has flow rate=0; tunnels lead to valves SS, JD
|
||||
Valve QO has flow rate=0; tunnels lead to valves AA, VH
|
||||
Valve SA has flow rate=0; tunnels lead to valves BM, KH
|
||||
Valve NV has flow rate=0; tunnels lead to valves AA, SG
|
||||
Valve ZK has flow rate=0; tunnels lead to valves CP, IV
|
||||
Valve ON has flow rate=0; tunnels lead to valves PC, KH
|
||||
Valve PN has flow rate=0; tunnels lead to valves HS, VH
|
||||
Valve RV has flow rate=0; tunnels lead to valves NJ, VH
|
||||
Valve RK has flow rate=0; tunnels lead to valves SS, JV
|
||||
Valve OC has flow rate=18; tunnel leads to valve HS
|
||||
Valve EF has flow rate=0; tunnels lead to valves LY, WL
|
||||
Valve VJ has flow rate=0; tunnels lead to valves TA, IR
|
||||
Valve LL has flow rate=5; tunnels lead to valves ZS, IT, SK, IS, WG
|
||||
Valve FF has flow rate=0; tunnels lead to valves HN, LY
|
||||
Valve LY has flow rate=21; tunnels lead to valves EF, FF, UR, JZ
|
||||
Valve EJ has flow rate=0; tunnels lead to valves WL, CP
|
||||
Valve NJ has flow rate=6; tunnels lead to valves RV, KD, SG, SI, TA
|
10
2022/day16-proboscidae_volcanium/tests/sample_input
Normal file
10
2022/day16-proboscidae_volcanium/tests/sample_input
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue