From 55b3cd16f722b5f52ed51aafc34ad8b7a6cd787f Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Thu, 19 Dec 2024 06:49:04 +0100 Subject: [PATCH] day 19 part1 --- days/2024/19.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++ examples/2024/19.txt | 10 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 days/2024/19.rs create mode 100644 examples/2024/19.txt diff --git a/days/2024/19.rs b/days/2024/19.rs new file mode 100644 index 0000000..6e5647b --- /dev/null +++ b/days/2024/19.rs @@ -0,0 +1,48 @@ +use advent_of_code::strings::convert_to_array; +#[allow(unused_imports)] +use advent_of_code_macros::{include_data, include_example}; + +include_data!(DATA 2024 19); + +fn test_pattern(pattern: String, parts: Vec) -> bool { + + false +} + +fn main() { + let (patterndata, designdata) = DATA.split_once("\n\n").unwrap(); + let mut designs = convert_to_array::<_, _, '\n'>(designdata, str::to_string); + let patterns = convert_to_array::<_, _, ','>(patterndata, str::to_string); + designs.sort(); + let mut possible = 0; + for design in designs { + let mut candidates = vec![design]; + 'designloop :loop { + let mut new = Vec::with_capacity(candidates.len()); + for possibility in candidates { + for part in patterns.clone() { + if possibility.starts_with(part.as_str()) { + if possibility.len() == part.len() { + println!("Found design"); + possible+=1; + break 'designloop; + } + new.push(possibility[part.len()..].to_owned()); + } + } + } + new.sort(); + new.dedup(); + candidates = new; + if candidates.len() == 0 { + break; + } + } + } + println!("There are {} possible designs", possible); +} + +#[cfg(test)] +mod test { + use super::*; +} diff --git a/examples/2024/19.txt b/examples/2024/19.txt new file mode 100644 index 0000000..29648be --- /dev/null +++ b/examples/2024/19.txt @@ -0,0 +1,10 @@ +r, wr, b, g, bwu, rb, gb, br + +brwrr +bggr +gbbr +rrbgbr +ubwu +bwurrg +brgr +bbrgwb