add until day05-1

This commit is contained in:
timeshifter
2026-06-05 22:12:35 +02:00
parent 89c728010c
commit c7a5adc00a
26 changed files with 2326 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
#[cfg(debug_assertions)]
const FILENAME: &str = "example.txt";
#[cfg(not(debug_assertions))]
const FILENAME: &str = "input.txt";
const VOWELS: &str = "aeiou";
const FORBIDDEN: [&str; 4] = ["ab", "cd", "pq", "xy"];
fn main() {
let data = std::fs::read_to_string(FILENAME).unwrap();
part_1_and_2(&data, is_nice_1);
part_1_and_2(&data, is_nice_2);
}
fn part_1_and_2<T: Fn(&&str) -> bool>(data: &str, f: T) {
let sum = data.lines().filter(f).count();
println!("{sum}");
}
fn is_nice_1(s: &&str) -> bool {
let vowel_count = s.chars().filter(|c| VOWELS.contains(*c)).count();
let double_letter = s.chars().zip(s.chars().skip(1)).any(|(a, b)| a == b);
let has_forbidden_tuple = s
.chars()
.zip(s.chars().skip(1))
.map(|(a, b)| format!("{a}{b}"))
.any(|tuple| FORBIDDEN.contains(&tuple.as_str()));
vowel_count >= 3 && double_letter && !has_forbidden_tuple
}
fn is_nice_2(s: &&str) -> bool {
let mut subrule_1 = false;
let mut subrule_2 = false;
subrule_1 && subrule_2
}