|
|
@ -1,18 +1,14 @@
|
|
|
|
use std::io;
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
|
|
|
|
use regex::Regex;
|
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
|
|
|
|
use day::Day;
|
|
|
|
pub fn solve(input: &str) -> i32 {
|
|
|
|
|
|
|
|
input.lines().filter(|&s| is_nice(&s.to_string())).count() as i32
|
|
|
|
pub struct Day05 {
|
|
|
|
|
|
|
|
input: String,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
|
|
|
impl Day05 {
|
|
|
|
|
|
|
|
fn is_nice(string: &String) -> bool {
|
|
|
|
fn is_nice(string: &String) -> bool {
|
|
|
|
Day05::has_pair_of_two_letters(string) &&
|
|
|
|
has_pair_of_two_letters(string) &&
|
|
|
|
Day05::has_letter_sandwich(string)
|
|
|
|
has_letter_sandwich(string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn has_three_vowels(string: &String) -> bool {
|
|
|
|
fn has_three_vowels(string: &String) -> bool {
|
|
|
@ -38,22 +34,11 @@ impl Day05 {
|
|
|
|
fn has_letter_sandwich(string: &String) -> bool {
|
|
|
|
fn has_letter_sandwich(string: &String) -> bool {
|
|
|
|
string.as_bytes().windows(3).any(|win| win[0] == win[2])
|
|
|
|
string.as_bytes().windows(3).any(|win| win[0] == win[2])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Day for Day05 {
|
|
|
|
|
|
|
|
fn new(input: String) -> Day05 {
|
|
|
|
|
|
|
|
Day05 { input: input }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn solve(&self) -> io::Result<i32> {
|
|
|
|
|
|
|
|
Ok(self.input.lines().filter(|&s| Day05::is_nice(&s.to_string())).count() as i32)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_nice() {
|
|
|
|
fn test_nice() {
|
|
|
|
assert!( Day05::is_nice(&"qjhvhtzxzqqjkmpb".to_string()));
|
|
|
|
assert!( is_nice(&"qjhvhtzxzqqjkmpb".to_string()));
|
|
|
|
assert!( Day05::is_nice(&"xxyxx ".to_string()));
|
|
|
|
assert!( is_nice(&"xxyxx ".to_string()));
|
|
|
|
assert!(!Day05::is_nice(&"uurcxstgmygtbstg ".to_string()));
|
|
|
|
assert!(!is_nice(&"uurcxstgmygtbstg ".to_string()));
|
|
|
|
assert!(!Day05::is_nice(&"ieodomkazucvgmuy ".to_string()));
|
|
|
|
assert!(!is_nice(&"ieodomkazucvgmuy ".to_string()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|