day 16 finished

This commit is contained in:
Rüdiger Ludwig 2023-07-26 22:09:11 +02:00
parent daa8b6b1d0
commit 6f3e94c5d1
6 changed files with 1081 additions and 94 deletions

View file

@ -1,5 +1,5 @@
use super::template::{DayTrait, ResultType};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use std::{iter::zip, num::ParseIntError};
use thiserror::Error;
@ -72,13 +72,14 @@ struct Monkey {
bad_monkey: usize,
}
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();
}
static MONKEY: Lazy<Regex> = Lazy::new(|| Regex::new(r"Monkey (\d+)").unwrap());
static STARTING: Lazy<Regex> =
Lazy::new(|| Regex::new(r"Starting items: (\d+(?:, \d+)*)").unwrap());
static OP: Lazy<Regex> =
Lazy::new(|| Regex::new(r"Operation: new = old ([+*] \d+|\* old)").unwrap());
static TEST: Lazy<Regex> = Lazy::new(|| Regex::new(r"Test: divisible by (\d+)").unwrap());
static NEXT: Lazy<Regex> =
Lazy::new(|| 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> {