use advent_of_code::strings::convert_to_array; use advent_of_code_macros::include_aoc; include_aoc!(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::*; }