1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
use crate::Input; pub fn solve(input: &mut Input) -> Result<usize, String> { let anagrams_are_equal = input.is_part_two(); Ok(input .text .lines() .filter(|passphrase| { let mut words: Vec<Vec<char>> = passphrase .split_ascii_whitespace() .map(|word| { let mut chars: Vec<char> = word.chars().collect(); if anagrams_are_equal { chars.sort_unstable(); } chars }) .collect(); words.sort(); let initial_len = words.len(); words.dedup(); initial_len == words.len() }) .count()) } #[test] fn test() { use crate::{test_part_one, test_part_two}; let real_input = include_str!("day04_input.txt"); test_part_one!(real_input => 325); test_part_two!(real_input => 119); }