add until day05-1
This commit is contained in:
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "day05"
|
||||
version = "0.1.0"
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "day05"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,9 @@
|
||||
ugknbfddgicrmopn
|
||||
aaa
|
||||
jchzalrnumimnmhp
|
||||
haegwjzuvuyypxyu
|
||||
dvszwmarrgswjxmb
|
||||
qjhvhtzxzqqjkmpb
|
||||
xxyxx
|
||||
uurcxstgmygtbstg
|
||||
ieodomkazucvgmuy
|
||||
+1000
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user