Dieser Commit ist enthalten in:
Sebastian Tobie 2024-12-19 06:49:04 +01:00
Ursprung fef542ba78
Commit 55b3cd16f7
2 geänderte Dateien mit 58 neuen und 0 gelöschten Zeilen

48
days/2024/19.rs Normale Datei
Datei anzeigen

@ -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<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];
'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::*;
}

10
examples/2024/19.txt Normale Datei
Datei anzeigen

@ -0,0 +1,10 @@
r, wr, b, g, bwu, rb, gb, br
brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb