2024-12-19 06:49:04 +01:00
|
|
|
use advent_of_code::strings::convert_to_array;
|
2024-12-19 17:12:39 +01:00
|
|
|
use advent_of_code_macros::include_aoc;
|
2024-12-19 06:49:04 +01:00
|
|
|
|
2024-12-19 17:12:39 +01:00
|
|
|
include_aoc!(2024, 19);
|
2024-12-19 06:49:04 +01:00
|
|
|
|
|
|
|
fn test_pattern(pattern: String, parts: Vec<String>) -> 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];
|
2024-12-19 17:12:39 +01:00
|
|
|
'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());
|
2024-12-19 06:49:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-19 17:12:39 +01:00
|
|
|
new.sort();
|
|
|
|
new.dedup();
|
|
|
|
candidates = new;
|
|
|
|
if candidates.len() == 0 {
|
|
|
|
break;
|
|
|
|
}
|
2024-12-19 06:49:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
println!("There are {} possible designs", possible);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
}
|