Started on aoc day 16 but it's pretty f'ing hard
This commit is contained in:
32
advent_of_code/2022/16/Cargo.lock
generated
Normal file
32
advent_of_code/2022/16/Cargo.lock
generated
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "main"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
9
advent_of_code/2022/16/Cargo.toml
Normal file
9
advent_of_code/2022/16/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "main"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nom = "7.1.2"
|
||||||
54
advent_of_code/2022/16/input.txt
Normal file
54
advent_of_code/2022/16/input.txt
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
Valve XG has flow rate=0; tunnels lead to valves CR, OH
|
||||||
|
Valve ZF has flow rate=7; tunnels lead to valves SC, BY, PM, LW, CJ
|
||||||
|
Valve RD has flow rate=13; tunnels lead to valves JS, VM
|
||||||
|
Valve XJ has flow rate=0; tunnels lead to valves JO, YO
|
||||||
|
Valve CJ has flow rate=0; tunnels lead to valves UA, ZF
|
||||||
|
Valve UA has flow rate=0; tunnels lead to valves ZP, CJ
|
||||||
|
Valve EQ has flow rate=0; tunnels lead to valves ZP, RP
|
||||||
|
Valve IU has flow rate=0; tunnels lead to valves EV, CN
|
||||||
|
Valve QM has flow rate=0; tunnels lead to valves XA, CN
|
||||||
|
Valve WC has flow rate=0; tunnels lead to valves JS, OH
|
||||||
|
Valve MU has flow rate=0; tunnels lead to valves AA, ZP
|
||||||
|
Valve MW has flow rate=11; tunnels lead to valves BM, AG, RG, NL
|
||||||
|
Valve XA has flow rate=0; tunnels lead to valves JO, QM
|
||||||
|
Valve OH has flow rate=12; tunnels lead to valves WC, YS, XG, KO
|
||||||
|
Valve QD has flow rate=20; tunnels lead to valves BY, KY, CR, RP
|
||||||
|
Valve OE has flow rate=0; tunnels lead to valves FB, BU
|
||||||
|
Valve CB has flow rate=0; tunnels lead to valves AA, FX
|
||||||
|
Valve TB has flow rate=23; tunnel leads to valve VM
|
||||||
|
Valve PM has flow rate=0; tunnels lead to valves ZF, AA
|
||||||
|
Valve YS has flow rate=0; tunnels lead to valves OH, RG
|
||||||
|
Valve KO has flow rate=0; tunnels lead to valves OH, VT
|
||||||
|
Valve AA has flow rate=0; tunnels lead to valves PM, MU, BM, AW, CB
|
||||||
|
Valve RG has flow rate=0; tunnels lead to valves YS, MW
|
||||||
|
Valve BU has flow rate=0; tunnels lead to valves OE, EV
|
||||||
|
Valve RK has flow rate=0; tunnels lead to valves KY, FX
|
||||||
|
Valve JO has flow rate=18; tunnels lead to valves NL, SX, XA, XJ
|
||||||
|
Valve AG has flow rate=0; tunnels lead to valves IS, MW
|
||||||
|
Valve AW has flow rate=0; tunnels lead to valves BS, AA
|
||||||
|
Valve ZP has flow rate=9; tunnels lead to valves UA, NG, DU, MU, EQ
|
||||||
|
Valve KY has flow rate=0; tunnels lead to valves QD, RK
|
||||||
|
Valve EV has flow rate=19; tunnels lead to valves VT, BU, IU, SX
|
||||||
|
Valve FB has flow rate=24; tunnel leads to valve OE
|
||||||
|
Valve DU has flow rate=0; tunnels lead to valves IS, ZP
|
||||||
|
Valve NG has flow rate=0; tunnels lead to valves FX, ZP
|
||||||
|
Valve HC has flow rate=0; tunnels lead to valves CN, HB
|
||||||
|
Valve SC has flow rate=0; tunnels lead to valves IS, ZF
|
||||||
|
Valve HB has flow rate=22; tunnel leads to valve HC
|
||||||
|
Valve VM has flow rate=0; tunnels lead to valves RD, TB
|
||||||
|
Valve LW has flow rate=0; tunnels lead to valves ZF, FX
|
||||||
|
Valve SX has flow rate=0; tunnels lead to valves EV, JO
|
||||||
|
Valve FX has flow rate=6; tunnels lead to valves FA, NG, RK, LW, CB
|
||||||
|
Valve JS has flow rate=0; tunnels lead to valves WC, RD
|
||||||
|
Valve BM has flow rate=0; tunnels lead to valves MW, AA
|
||||||
|
Valve FA has flow rate=0; tunnels lead to valves IS, FX
|
||||||
|
Valve RP has flow rate=0; tunnels lead to valves QD, EQ
|
||||||
|
Valve NL has flow rate=0; tunnels lead to valves MW, JO
|
||||||
|
Valve CN has flow rate=15; tunnels lead to valves HC, QM, IU
|
||||||
|
Valve BS has flow rate=0; tunnels lead to valves IS, AW
|
||||||
|
Valve KP has flow rate=25; tunnel leads to valve YO
|
||||||
|
Valve YO has flow rate=0; tunnels lead to valves XJ, KP
|
||||||
|
Valve CR has flow rate=0; tunnels lead to valves XG, QD
|
||||||
|
Valve BY has flow rate=0; tunnels lead to valves QD, ZF
|
||||||
|
Valve IS has flow rate=5; tunnels lead to valves DU, SC, AG, FA, BS
|
||||||
|
Valve VT has flow rate=0; tunnels lead to valves KO, EV
|
||||||
63
advent_of_code/2022/16/src/main.rs
Normal file
63
advent_of_code/2022/16/src/main.rs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
use nom::{
|
||||||
|
IResult,
|
||||||
|
multi::separated_list1,
|
||||||
|
sequence::{tuple, preceded},
|
||||||
|
character::complete::{self, multispace1},
|
||||||
|
bytes::complete::take,
|
||||||
|
bytes::streaming::tag,
|
||||||
|
branch::alt, Parser,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, PartialOrd, Clone)]
|
||||||
|
struct Valve {
|
||||||
|
id: String,
|
||||||
|
flow: u32,
|
||||||
|
tunnels: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_input(input: &str) -> IResult<&str, Vec<(String, u32, Vec<String>)>> {
|
||||||
|
let (input, valve_tuples) = separated_list1(
|
||||||
|
multispace1,
|
||||||
|
tuple((
|
||||||
|
preceded(
|
||||||
|
tag("Valve "),
|
||||||
|
take(2 as usize).map(|s| String::from(s))),
|
||||||
|
preceded(
|
||||||
|
tag(" has flow rate="),
|
||||||
|
complete::u32),
|
||||||
|
alt((
|
||||||
|
preceded(
|
||||||
|
tag("; tunnels lead to valves "),
|
||||||
|
separated_list1(
|
||||||
|
tag(", "),
|
||||||
|
take(2 as usize).map(|s| String::from(s)))),
|
||||||
|
preceded(
|
||||||
|
tag("; tunnel leads to valve "),
|
||||||
|
take(2 as usize).map(|s| vec![String::from(s)])),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
)(input)?;
|
||||||
|
|
||||||
|
Ok((input, valve_tuples))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input_text = include_str!("../test.txt");
|
||||||
|
let (_rest, valve_tuples) = parse_input(input_text).unwrap();
|
||||||
|
|
||||||
|
// Test the parsing
|
||||||
|
// for vt in &valve_tuples {
|
||||||
|
// print!("Valve {} has flow rate={}; tunnels lead to valves ", vt.0.as_str(), vt.1);
|
||||||
|
// for v in &vt.2 {
|
||||||
|
// print!("{}, ", v.as_str());
|
||||||
|
// }
|
||||||
|
// println!();
|
||||||
|
// }
|
||||||
|
|
||||||
|
let valves : Vec<Valve> = valve_tuples
|
||||||
|
.into_iter()
|
||||||
|
.map(|(i, f, t)| Valve {id: i, flow: f, tunnels: t})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
10
advent_of_code/2022/16/test.txt
Normal file
10
advent_of_code/2022/16/test.txt
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
|
||||||
Reference in New Issue
Block a user