static INPUT: &str = include_str!("input.txt"); fn main() { let valueified = INPUT.split('\n').filter(|s| !s.is_empty()); let nice_count = valueified.clone().filter(|s| { let mut s2 = s.chars(); let mut last_char = s2.next().unwrap(); let mut double_flag = false; let mut abcdpqxy_flag = false; for c in s2 { if c == last_char { double_flag = true; } if [('a','b'),('c','d'),('p','q'),('x','y')].contains(&(last_char, c)) { abcdpqxy_flag = true; } if double_flag && abcdpqxy_flag { break; } last_char = c; } s.chars().filter(|c| "aeiou".contains(*c)).count() >= 3 && double_flag && !abcdpqxy_flag }).count(); println!("Nice word count: {nice_count}"); let nice_count = valueified.filter(|s| { let mut s = s.chars(); let mut llc = s.next().unwrap(); let mut lc = s.next().unwrap(); let mut dupeslist = Vec::with_capacity(32); dupeslist.push((llc, lc)); let mut pushed = true; let mut flag1 = false; let mut flag2 = false; for c in s { if !flag1 && (!pushed || llc != lc || lc != c) && dupeslist.contains(&(lc, c)) { flag1 = true; } if !flag1 && !dupeslist.contains(&(lc, c)) { dupeslist.push((lc, c)); pushed = true; } else { pushed = false; } if c == llc { flag2 = true; } if flag1 && flag2 { break; } llc = lc; lc = c; } flag1 && flag2 }).count(); println!("Nice word(v2) count: {nice_count}"); }