diff --git a/.vscode/launch.json b/.vscode/launch.json index f6b3fe2..d1f66fe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,15 +7,15 @@ { "type": "lldb", "request": "launch", - "name": "Debug executable 'advent2022'", + "name": "Debug executable 'advent2019'", "cargo": { "args": [ "build", - "--bin=advent2022", - "--package=advent2022" + "--bin=advent2019", + "--package=advent2019" ], "filter": { - "name": "advent2022", + "name": "advent2019", "kind": "bin" } }, @@ -30,16 +30,16 @@ { "type": "lldb", "request": "launch", - "name": "Debug unit tests in executable 'advent2022'", + "name": "Debug unit tests in executable 'advent2019'", "cargo": { "args": [ "test", "--no-run", - "--bin=advent2022", - "--package=advent2022" + "--bin=advent2019", + "--package=advent2019" ], "filter": { - "name": "advent2022", + "name": "advent2019", "kind": "bin" } }, diff --git a/.vscode/settings.json b/.vscode/settings.json index 5f484b7..23fd35f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,3 @@ { - "editor.formatOnSave": true, - "debug.allowBreakpointsEverywhere": true + "editor.formatOnSave": true } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index cbeeee5..d4af544 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" anyhow = "1.0" const_format = "0.2.31" itertools = "0.11" +lazy_static = "1.4" num-traits = "0.2" once_cell = "1.18.0" regex = "1.7" diff --git a/data/day17/blocks.txt b/data/day17/blocks.txt deleted file mode 100644 index fbcc382..0000000 --- a/data/day17/blocks.txt +++ /dev/null @@ -1,17 +0,0 @@ -#### - -.#. -### -.#. - -..# -..# -### - -# -# -# -# - -## -## \ No newline at end of file diff --git a/data/day17/example01.txt b/data/day17/example01.txt deleted file mode 100644 index fb5d89e..0000000 --- a/data/day17/example01.txt +++ /dev/null @@ -1 +0,0 @@ ->>><<><>><<<>><>>><<<>>><<<><<<>><>><<>> \ No newline at end of file diff --git a/data/day17/input.txt b/data/day17/input.txt deleted file mode 100644 index 9906efb..0000000 --- a/data/day17/input.txt +++ /dev/null @@ -1 +0,0 @@ -><<>>>><>>><<>><<>><<<<>>><<<<>><<<>>>><<>><><<<><<<>><>>>><<<>><<<<><<><<<>>><>><<<<>><>>><<<<>>>><<>>>><<<>><><<<<><<>>><>>>><>>><>>>><<<<><<>>><<>>><<<<>>>><<<><>><<>><<<<>>><<<>>>><>><>>>><>>><<<<><<>><>>>><<<<><<>>>><<>>><>><<<>><<<<>>>><<<>>>><<<>>>><<<<>>><<<<>>><>><<>>>><<><<<<>><<>><<>>><<<>>>><>><<>>>><<>><<<<>>>><<>>>><>><>>><<<<><<>><<>>>><<><<<>>>><>>><<<<>>><<<>><<<><>>>><<<<><<<<>>><<<<><<<>><>><<<<>>>><<>>><<>><<>><<<><<<<><<<>>>><<<><<<<><<<<>><<<<>>><>>><<<<>>><<<><<<><>><<<<>><<<><<<<>>>><<>><<>>><<<<>>>><<><<<<>>>><<>>>><<<>>><<>><<><<<><<<<>>><<<<><><>>><<<<>>><<<>>><>>>><<<>>>><>>>><<<<>>><<<>><<>><<><<<<>>>><<<><<<<><<<<>><<<<>>>><>>>><<>>><<<<>><<<>>>><<><><<<<>>><>>>><<<>>><<<>>><>>>><>><<>>><>><<<><<<>>>><<<<>>>><><<>>><>><<<>>><<<>>><<<<>>>><<<<>>>><<>>><<<><<>><<<<><<<<>>>><><<>>>><<>>><<>>>><<<>>><<>><<>>><>>>><<<<>>>><<>>>><<>>>><<>>><<<>>><<<>>>><><<<<>>><>>>><<<>><<<>>>><<>>>><<<<>>><>>>><<<>>>><<>><>>>><<<>><<<><<<>>>><><<>>><<><<>>><<>>>><<>>>><<<>>><<<>><<><>><<<<>>><<<><<>>>><<<>>><<><<<<><<><<<<>>>><<<<>>>><<<><>>><>>><<<<><<<<><>><<<<>>>><<>>><>>><<<<>><><<<>>>><>>><<<>><>>>><<<<>>><<<>>>><<>><>><<<>><<<<>>>><<<<>>><<<<><<>>>><<>><<<>><<<>><<<><<><<<<>><<>>><<>><<<>>><<<<>><>>><<<>>>><<<<><<>>><<<<>><<<>>>><<<><<<><<>>><<>>>><<<<>>>><<<><<<>>>><<<<>>>><<<>><>>><<>>>><><<<<><<<<>><<><>>><>><<>>>><<<<><><<<<>>><<<>>>><<<>><<<>>><<<>>><<>><>>><<<><><>>>><>><>><<<>><<<<>><<<>>>><<<<>>><<<<>><>>>><>>>><<<>><>><<>>><<<<>><>>><<<>><>><<>>>><<<<>>><<>>>><<<><<>><<>>>><>><>>><<><>><<>>>><<<>><><<>>>><<<>>><<>><<<>>><>>>><>><<>><>><<<<>>><>>><<>><<>>>><<<><<<<><<>>>><<>><<>>><>>><<<>>><<>>>><<<<><<><><<<<>>>><<<<>>><<<><>>><<<<>>>><<<>><>>><<<>><<<>>>><<>><<<><<><<<<><><>>>><<>><>>>><>>>><<<<>>><<>><<<<>><<>>><<<>><<<<><<<>>><<<>>>><<><<><<<<>><>>><<><<<<>><<><><>><<<><<<<>><<<><<>><<>><>>><>>><<<<>>>><>>>><<<<><>><<<<>>>><<<<>>><<<<>>>><<<>>><<>><>><>>><<>><<<>>><<<>>><<<<>>>><<<<>>><<<>>>><>>>><><><<>>>><<>>>><<<<>>><<<<>>>><<>>><>><<<<>>><<<<>>>><<<><<<<>>>><<>>><<<><>><<>>>><<<>>><<<>>><>>><<<>>>><<<<>>>><<<><<>><<<><>>>><<>>><<>>>><>>><<>><<<>>>><<<<>>>><<<<>>><>>>><><<<<>><><<><><<<<><<<<>>>><><<><<<<>><<<<><<<<>>>><<<>>><<<<>>><>>><<>>><<<>><<<<>><>>><<<<><>><<<<>>>><>>>><<>>><>><>>><>>>><>><<<<>>><<<>><<<>>><<>>><<<>>>><<><<<<>>>><<<<>>><<<<>><<<<>>>><>>>><<<<>>>><<<>>>><><<<<>>>><<>><<<>><<<>>>><<>>><<<<>>><>>>><<<>><>>>><<>>>><<>>>><<><><<><<>><<<<>>><<<<>><<<>><>>><>>>><<<>>>><<>><><<<><<<<>>>><<><<<<><<<>>><<<><>>>><<>>>><<<<>><<<>><><<<>><<<<><<<>>>><<><><<<<>>><><>>>><>>>><<<<>><<><>>><<>>>><<>>><>>><<>><<<>><><><><>><<>>><>><<<>>>><<<>><>>><>>>><>><<>>><<>>>><<<<>>><<>><<<<>>><>><<<<>>><>>>><><<<>><<<>>><<<<>>><<><<<><<<<>>><>>><><<<<><<<>>><<>><><<<<>><<<><><<<<>>>><<<><><<>>><<<>><>>><<>><<<<><>><<><<<<>><<<>><>>><>>>><<<><<<>><<>><<<<>>>><<>><>>><>>><<<<>>><>>>><<<<>>>><<>>><<>>>><<<<><<<><<<>><<<<>><<<>>><<<<>>>><<<>>>><<>>>><<<<><<<<>>><<<<>><<><<<<><>><<<>><<<<><<>>>><<<><<<<>><<<<><><<<>>><>>>><<<<>>><<<<>><>><<<<><<<><<<>>><<<><<>>><<<><<<>>>><<<>>><<<><<<><<><<<>>><<<<>><>>>><<<<>>><<<>>><<<<><<>>><<<<>>><<<<>><>>><<><<<><<<<><<>><<<>>><<><<<>><<<<>><<>>><<<<><<<>>>><>>><<<<><>>>><<<<><<<<>><<>>><<><<<<>><<><>>><<<<>>><<<>><<<>>>><>><<>>><>>>><>>>><<<<>><<><<<>>>><<>><<<<>>><<>>><<>><<>><>>>><<><<<<>>><>>>><<>>>><<>><>>><<<<>>>><<<><>>><<>>><>>>><<<<><<>><<<>>>><<>><<<<>><<<><<>>>><>>>><<<<><><<<><<<<>><<<>>>><>>>><<<><><<<><<<>>><>>><<<>><<<>>>><<<><<<>>><<<<>>><<>>><<<>><>><>><<>>>><>><<<>>><<<><<<<>>><<<>>>><<>>><>><<>>>><<>>>><<>>><<><<>><<>>><<<<>>><<<<>><<<<>>>><<<>>>><<<<>><<>><<<<>><<<>>>><<>>>><>>><<<>><>>><>><<<><<<><<>>>><<<<>><><>><<<<>>>><<>>>><<>>>><<<>>><<<>>><<<<>>>><>>>><><<><<>>>><<>>>><>><<>><>><<>><<>><<<>>>><<>><<><<><<><<<<>>><<<<><><>>><<<>><><<<><<<<>><<>>>><<>><<<<>><<>><<>>><<><<>>>><>><<<<>>><><<>><>>>><<<<>>><<>>>><<><<<>>>><><<<>><>><<>><<><<<<>>><<><><<<<>>>><>>><><<>>>><<>>><>>>><<<<>>>><<>><<<>><<<>>>><>>>><<<><>><<>><<<<>>>><<<>>>><<<>>>><<<>><<<<>><<<<><<<<>>>><<>><<<<><<>><<<>>><<>>>><<<<>>>><>>>><<>>>><<<<>>><<<<>><<<>><<>>>><>><<>><<>><<>><<<<>>>><<<><<>>><<<><<<<>><<>><<<<>>><<<<>>><<<><>>>><<<<>>><<<<>>><>><<>>>><<<<><<<<>>>><<<<><<>>><<<<><<><<<>>><>><<<<>>>><<<><<<>>>><>>>><<<>><><<<<><<<>>><<>>><<<<>><<<<>>><<>>><<>>><<<<><<<>><>>>><>><<<<>>><>>><<>>><<>>><<><<>>>><<<>>>><<<>>><>>><<<>><>>>><<<>>><><<>>>><<<<>>><>>><<<<>>>><<<>><<<><<>>><<<>>><<<<>><<<<>><>><<<>><<<<>>>><<><>><>>>><<<<>>><>>><<<<>>><>>><>>><<<>>><<<><<<>><>><<<><<>>><>>><<<<>>><<<<>>><<>>>><>>><<<>>>><<<<><<>><<><><<<><<>><>><<<>>><<<<>>><>>><<<>>>><<<<>>>><<<>>><><<<<>>><<>>><<>>>><<>><<<<><>>><<<>>>><<><<><<>>><<><<<><<<>>>><>>><><><>>>><<>>><><<<>><><<>><><>><>>><><<<><<><>>><<<<>><<<<>>><>>><<>><<>>>><<<<><<<><<<<>>><<<<>><<<<>>><<>><<<>><<>><<>>>><<<<>>>><<>><<<><>><<<<>>>><<>><<><<<>><<>><>><<<>><<<>><<<>>>><<>>><<>><<<>><<>>><><>><<>>><>>><<<<>>><<<<>><<><>>><><<>>>><<><><<<>><>><<>>>><<<>>>><<<>><>>>><<<<>><<>>>><>>>><<<>><<>><>>><<<<><><><<<>>>><>>>><<><<<><><<<>>>><<<<>>>><><><<<>>><<<>><<<>>><<<<>>>><<<<>>><<>><><<<>>>><<>>><>>>><<<<>>><>>>><<<><<<>><<<>><<<><<<><<<>>>><<<<>>><<>>><>>><<>><>>>><<>>>><<>>>><<<>>>><<<>>><>>><<<<><><<>>><<<<>>><>><<<<>><>><<<><><<<<><>>><<<>>>><>>>><>>>><<<><<<<><<<<>>><<<>><<<>>><<>>>><<>>>><<<<>><<<>>><<<>>>><<<<><<>>>><<>><<<>><<<<><<><><<><>>><><<<><<<<>>><>>>><<><<<<>>>><>>>><>>><<>>><<<<>>><><<<<>>>><>>><<>><<<>>>><<>>>><<<>>>><<><<>>>><>><<<<><<><<<<>><<<><<<>>>><><>>><<>>>><<>><>><<<<>><<<>>>><>><<<>><<<>><<<><<<>><<<>><><<<<>>>><<>>><<<>>><<>>><>>>><>>>><<><<<>>>><<>>><>><<<<>><<><<<>>>><<>>>><>><<<<>>><<<<>>>><<<<><<<<>><<>>><>>><<<<>>>><<<>>><>><<<<>>><><<<<><<>>><<>>><><<<><<<<>><>>><<<<><<<><<><<<<><<<<>><<<<><<<<>>>><<<<>><>>>><>>><<<<><<>><>><<>>>><<<<>><<<<>>><>>><<<>>><<<>>><<<<>>><>>><<<<>>>><<<><<<><<<><<><<<>><<<>><<<>>><>><<>>><<>><<<<>>><<<<>><<<<><>>>><>>>><<<>>><<<>>><<><<<>>>><<<><<>><<>>><<><<<<><<<<>><<<>><>>><<<<>><<><<<<>>><<>><<<><>><<<<>><<<>><<>>><<<<><<>>>><<><<>>>><<<<>>>><<<><<<><<<<>>>><<<<><<>>>><<>>>><>>><<<>>>><<<<>>>><>>>><>>>><<<<><<><>><<><<>>>><>>>><><<<<>><<<<>><<>>><<>><>>>><<><<><<>><<<<>>><<<<>>>><<>><<>><<><><>><<<>>>><<<><<<>><<<<><<<<>>>><<<<>>>><<<>>><<><<>>>><<<><><<>>>><<<><<<><<<<>><>>>><<><<<><>>>><<>>>><<<<>><<<>><<>><<>><<>>>><<>>><>>>><>>><<>>>><<<>><<<>><<>><<<><<>><<<<>><<>>>><<<>>>><<<>>>><<><<<<><<<>>>><>>><<<><<<>>><<<<>>>><<><<<<>><<<>>><>>>><<<>>><<<<>>><<<>>>><>>>><<<<><<>><<<<>><><<<>><<>><<<>><<>>>><>>>><><<<>>>><<>>><<<>>>><<<<>><<>>>><<><<<<>><<<<>>><><<>><<<><<<>>>><<<><<<<>>><>>>><<<>><<>>><<>><><<><<<<><>>><>>>><>><>><<<>>>><<<<><<<<>>>><>>><<><<<>><<<>><>><>>>><><<>>>><>>><<<<><<<><>><><>>><<<><<<><<<<>>><<<>>><<<>><<<>>>><<<>>>><<<>>>><<<>>>><<<<>>><<<<><>>><><<<>>>><>>><<>><>><<<>>>><<<<><<>>>><>>><>>><<<>><<<<>>><<<><>>><>>><<><<><<<>>><<<<>>>><<<<>>>><>><<<<><<>>><<<<>>>><<>>><<<<><>><<>>><><<<<>>>><>>><<<<><<<<>>><<<<><<>>>><<<<>>>><<<<>>><<<>><>>><>>><<<<>>><>><<>><<><<<>>><<<><<<<>>>><>>>><<<<><<<<><<>>><<<>><>>><<<<>>>><<<><<<>><<>>>><><><<<<>><<<<><<<<><<<>>><<<>>><>><<<<>><<<<>><<<>>>><>><<>><<<<>>>><<<<>>>><<<>>><<<<>>><<<<>>><<<><<<<>>>><<>>>><<>>><<<>>>><><<<<><<<<><<>><>>>><>>><<<>><>>><<<<><<<<><<>>><>>><><<<><<>><<>>><<>>>><<<><>>>><<<>><<<><<>><<>>><<<<>>><<><<><><>>><><<>>><<<<><<<>>>><<<>>>><>>><<>>>><<<><<<>><<<>><<<<>>><<><<><<<<>>>><<>>>><>>><<>>>><><<<<>>><<<<>><<><<>>>><<<<>><<<<>>><<<<>>>><<<>>>><>>>><<<<>>>><>><<>>><<<><>>>><<>>>><<<>>><<>>>><<<>><<<>>>><<>><<<>>><<>><<><>><<><<<>>><<<>>><<<<>><<>>><>>>><<<<><<<><><>>><<<>><<<<>>><<>>>><>><>>>><<<<>>>><>>>><<<><<>>>><<<<><<<>>>><<<><><<<<>><<>>>><>>><<><>>><<>>>><>>><<>>><><<>>>><<<<>><>>><<<><<>><<<<>>><<<>><<<<>>><<>>><>><<<>><>>><<<<>>>><<<>><<>>><<<<><<>>>><<<<>>>><<><><<<<><<<>>>><<>>><<<<>>><<>>><<<<>><<<<><<>>>><<><>>><<<>><<<><<<>>><<<<>><<><>>>><<<><>><<>><>>>><<<<>><<<<>><><<<<><<<>>><<<<>><><>><<<<>>><>>>><<<<>>>><><<<<>>><<<<>>><<<<><><<<<>>>><<<>>>><<<<>><<>>><<<<>><<<><<>><><<<><<<>>><<<<>>>><<>>>><<>><<>>>><<<<>>><>><<><<>><<>><<<<><<<<>><<<>><<<>><<>>>><<<>>>><<<<>><>><>>>><<><<<<>><<<>><<<>><>>>><<<>>>><>>><<<<>>>><<<>>>><<><>>>><<<<><<>>>><<>>><<<<><<><<<<>>>><<>>><<><<<><<>><<<>><<>><<<><><<<<>>><<<<><<><<>><<>>><<<<>>><>>>><>>>><>>><><<<>><><<<>>>><<>>><<<<><<<><<<<><<<>>>><<>><>>><<<>>><>>><<>>>><>>>><>>>><<<>>>><>><<<><>><<<>>>><<>>><<>><>>>><>><<<<>>><<>><<><>>><><<<<>>>><<<><<<<>>><>>>><<><<<>>>><>>><<<<>><<>><<>>><>><>>><<<>>><>>>><<<><<<>>>><<<<>><<<>>><<<>>>><><<>><<><<<>>><><<<<><>>>><<<<>>><<><>>>><><<<<>>>><<<<>>>><><<><<>>><>><<<<>>><<<<><>>>><<>><<<<>>><>><<><<><<<>>>><<<<>><<<<>>>><>><<<<>>>><<<>>><<>>><><<<<><<<<>>><<>>><<<>>>><<<>>><><>><>>>><<<<><<>><<<<>>>><<<<>>>><<<<><<<><><>><><<<>>>><<<<>><<>><>>><<<>>><>>><<><<><>><>><<<>>>><<<<>>><><<<<><<<>>><<><<<>>><<<<><<<>>><<<>>>><<>>>><<>><>>><><<><<<>><>><<<<>><<>><>><<<<><<<<><>>>><<<<>>><<<><<<>><<><<<<>>><<<>>><>><><>>>><<<><>><<<<><>><<<<>>><><<><>><><<<<>>>><<><<<>>><<>>>><<<<>><<<>>><>>>><<>><>><<<<>>><<<>><><><>>>><<<>><<<<><<<>><<<<>><<<>>>><<>>><<<<>><><<>><<<>><<<<>>><<<>><>>>><<><<><>>>><<<><<>>>><><<<>><<>>><>><<<<>>><<<<><<<>>><<<<>>>><<>>>><<<>><<>><<<<>>><<<<>><>><<<>><<>>>><><<<>>>><<<>><>>>><<<>>>><<<<><<>><<<<>>><<>><><<>>><<<>><<>><<<>><<>>><<>>><<<>><<<>>><<>><<>><<<<>>>><<<<>>>><<<<><<>><<<>>><<<>>>><<<>><>>><><>><>>><><<>>>><>>><<<<>>>><<<>>>><>>><<<><<<>>><<<>><>>>><<<<>>><<<<><<<>>><<>>><<<>><<<<>><<<><<<>>>><><<<<>><<<<>>>><<<><<<>>><<<><<<<><>><>><<>>><<<>>><>>><><<<><<>>>><<<>>><>>><>>><>>>><<<><<<<>>>><<><<>><<<><<<><<<<><>><<><<<>>><<>>><<><<>>><<<<>><>><<<>>><<<<>>><>>><<<<>><>><<<<>><<>>>><<>>><>><<>><<<>><<<>>><<<<>><<<><<<>>>><<<>>><<>><<<<>><<<<>>><<<<>>>><<<>><<<<>>><>><<>>><<<>>><<<>>>><<<<>>>><<<><<<>>><<<>>><>>><>><<<<><><<<>><<<>>>><<<>>>><<<<>>>><<>><<>>><>><<<>>><<>><>><>><<<>>><>>><<<<>>><<<><<<>>><<<>><<<>><<<<>>><<<<>><<><><>>><<><<<<>>><<<<><<>><<<>><>><<<>>><<<>>>><<<<>>>><>>><<>>><<<<>><<<<>>>><<<>><<<>>><<<<><<<<><><<<>><>><<<<>><>>><<<><<<<>>><<<>><<<<><<<<>><>>><>><<><<>>>><<<<><<><<<<><<<<>>><<<><<<<>>><<<<><<<>>><<< \ No newline at end of file diff --git a/src/days/day11/mod.rs b/src/days/day11/mod.rs index 2e8b3c7..0f2cd1e 100644 --- a/src/days/day11/mod.rs +++ b/src/days/day11/mod.rs @@ -1,5 +1,5 @@ use super::template::{DayTrait, ResultType}; -use once_cell::sync::Lazy; +use lazy_static::lazy_static; use regex::Regex; use std::{iter::zip, num::ParseIntError}; use thiserror::Error; @@ -72,14 +72,13 @@ struct Monkey { bad_monkey: usize, } -static MONKEY: Lazy = Lazy::new(|| Regex::new(r"Monkey (\d+)").unwrap()); -static STARTING: Lazy = - Lazy::new(|| Regex::new(r"Starting items: (\d+(?:, \d+)*)").unwrap()); -static OP: Lazy = - Lazy::new(|| Regex::new(r"Operation: new = old ([+*] \d+|\* old)").unwrap()); -static TEST: Lazy = Lazy::new(|| Regex::new(r"Test: divisible by (\d+)").unwrap()); -static NEXT: Lazy = - Lazy::new(|| Regex::new(r"If (?:true|false): throw to monkey (\d+)").unwrap()); +lazy_static! { + static ref MONKEY: Regex = Regex::new(r"Monkey (\d+)").unwrap(); + static ref STARTING: Regex = Regex::new(r"Starting items: (\d+(?:, \d+)*)").unwrap(); + static ref OP: Regex = Regex::new(r"Operation: new = old ([+*] \d+|\* old)").unwrap(); + static ref TEST: Regex = Regex::new(r"Test: divisible by (\d+)").unwrap(); + static ref NEXT: Regex = Regex::new(r"If (?:true|false): throw to monkey (\d+)").unwrap(); +} impl Monkey { fn parse_line<'a>(re: &Regex, line: &'a str) -> Result<&'a str, MonkeyError> { diff --git a/src/days/day15/mod.rs b/src/days/day15/mod.rs index 28e4ee4..0614b9e 100644 --- a/src/days/day15/mod.rs +++ b/src/days/day15/mod.rs @@ -1,7 +1,7 @@ use super::template::{DayTrait, ResultType}; use crate::common::pos::Pos; use itertools::Itertools; -use once_cell::sync::Lazy; +use lazy_static::lazy_static; use regex::Regex; use std::{collections::HashSet, num::ParseIntError}; use thiserror::Error; @@ -209,8 +209,9 @@ struct Sensor { radius: i64, } -static SENSOR: Lazy = - Lazy::new(|| Regex::new(r"x=(-?\d+), y=(-?\d+).*x=(-?\d+), y=(-?\d+)").unwrap()); +lazy_static! { + static ref SENSOR: Regex = Regex::new(r"x=(-?\d+), y=(-?\d+).*x=(-?\d+), y=(-?\d+)").unwrap(); +} impl Sensor { pub fn parse(line: &str) -> Result<(Sensor, Pos), SensorError> { diff --git a/src/days/day16/mod.rs b/src/days/day16/mod.rs index 1e7cfb1..1f5e13b 100644 --- a/src/days/day16/mod.rs +++ b/src/days/day16/mod.rs @@ -1,13 +1,7 @@ -use std::collections::HashMap; -use std::fmt::{Debug, Display}; -use std::hash::Hash; -use std::iter::Sum; -use std::ops::{Add, Deref, Mul, Sub}; -use std::{collections::BinaryHeap, num::ParseIntError}; +use std::num::ParseIntError; use super::template::{DayTrait, ResultType}; use const_format::concatcp; -use itertools::Itertools; use once_cell::sync::Lazy; use regex::Regex; use thiserror::Error; @@ -22,106 +16,11 @@ impl DayTrait for Day { } fn part1(&self, lines: &[String]) -> anyhow::Result { - let system = ValveSystem::build(lines, "AA")?; - let result = system.maximum_flow(system.single_actor(Time(30)))?; - Ok(ResultType::Integer(*result)) + Ok(ResultType::Nothing) } fn part2(&self, lines: &[String]) -> anyhow::Result { - let system = ValveSystem::build(lines, "AA")?; - let result = system.maximum_flow(system.double_actor(Time(26)))?; - Ok(ResultType::Integer(*result)) - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -struct Time(usize); - -impl Time { - #[inline] - fn sub_to_zero(&self, other: Time) -> Time { - if self.0 > other.0 { - Time(self.0 - other.0) - } else { - Time(0) - } - } - - #[inline] - fn inc(&self) -> Self { - Self(self.0 + 1) - } -} - -impl Deref for Time { - type Target = usize; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl Add for Time { - type Output = Self; - - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self(self.0 + rhs.0) - } -} - -impl Sub for Time { - type Output = Self; - - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Self(self.0 - rhs.0) - } -} - -impl Mul for Time { - type Output = Flow; - - fn mul(self, rhs: Flow) -> Self::Output { - Flow(self.0 as i64 * *rhs) - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -struct Flow(i64); -impl Deref for Flow { - type Target = i64; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl Add for Flow { - type Output = Self; - - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self(self.0 + rhs.0) - } -} - -impl Sum for Flow { - fn sum>(iter: I) -> Self { - iter.fold(Self(0), |a, b| a + b) - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -struct Index(usize); - -impl Deref for Index { - type Target = usize; - - fn deref(&self) -> &Self::Target { - &self.0 + Ok(ResultType::Nothing) } } @@ -130,14 +29,8 @@ enum ValveError { #[error("Not an Integer")] NotAnInt(#[from] ParseIntError), - #[error("Not a valid description: {0}")] - CouldNotParse(String), - #[error("Not a valid valve: {0}")] - ValveNotFound(String), - - #[error("Did nt find optimum flow")] - NoOptimumFound, + NotAValidValve(String), } const ID: &str = "[[:alpha:]]+"; @@ -153,759 +46,80 @@ const PLURAL_STR: &str = concatcp!( const SINGULAR_STR: &str = concatcp!(COMMON, "tunnel leads to valve (?", ID, ")$"); #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] -struct RawValve<'a> { - id: &'a str, - flow: Flow, - neighbors: Vec<&'a str>, +struct Valve { + id: String, + rate: i64, + distances: Vec<(String, i64)>, } -impl<'a> RawValve<'a> { - fn create(id: &'a str, flow: Flow, neighbors: Vec<&'a str>) -> Self { - RawValve { - id, - flow, - neighbors, - } - } - - fn from_regex(regex: &Regex, line: &'a str) -> Option, ValveError>> { +impl Valve { + fn from_regex(regex: &Regex, line: &str) -> Option> { regex.captures(line).map(|caps| { match (caps.name("id"), caps.name("rate"), caps.name("exits")) { (Some(id), Some(rate), Some(exits)) => { let rate = rate.as_str().parse()?; - let neighbors = exits.as_str().split(",").map(|s| s.trim_start()).collect(); - Ok(RawValve::create(id.as_str(), Flow(rate), neighbors)) + let distances = exits + .as_str() + .split(",") + .map(|s| (s.trim_start().to_string(), 1)) + .collect(); + Ok(Valve { + id: id.as_str().to_string(), + rate, + distances, + }) } - _ => Err(ValveError::CouldNotParse(line.to_string())), + _ => Err(ValveError::NotAValidValve(line.to_string())), } }) } + + pub fn known_distances(&self) -> usize { + self.distances.len() + 1 + } + + pub fn steps_to(&self, to: &str) -> Option { + self.distances + .iter() + .find_map(|(other, distance)| if other == to { Some(*distance) } else { None }) + .or_else(|| (to == self.id).then_some(0)) + } } -impl<'a> TryFrom<&'a str> for RawValve<'a> { +impl TryFrom<&str> for Valve { type Error = ValveError; - fn try_from(value: &'a str) -> Result, Self::Error> { + fn try_from(value: &str) -> Result { static PLURAL: Lazy = Lazy::new(|| Regex::new(PLURAL_STR).unwrap()); static SINGULAR: Lazy = Lazy::new(|| Regex::new(SINGULAR_STR).unwrap()); - RawValve::from_regex(&PLURAL, value) - .or_else(|| RawValve::from_regex(&SINGULAR, value)) - .unwrap_or_else(|| Err(ValveError::CouldNotParse(value.to_string()))) + Valve::from_regex(&PLURAL, value) + .or_else(|| Valve::from_regex(&SINGULAR, value)) + .unwrap_or_else(|| Err(ValveError::NotAValidValve(value.to_string()))) } } -#[derive(Debug)] -struct Valve { - id: String, - idx: Index, - flow: Flow, - distances: Vec