forked from AlexAegis/advent-of-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
33 lines (30 loc) · 829 Bytes
/
lib.rs
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
use fancy_regex::Regex;
pub struct PartOne;
pub struct PartTwo;
impl aoclib::Solvable<&str, u32> for PartOne {
fn solve(input: &str) -> aoclib::Solution<u32> {
let r1 = Regex::new(r"ab|cd|pq|xy")?;
let r2 = Regex::new(r"(.*[aeiou]){3}")?;
let r3 = Regex::new(r"(.)\1")?;
Ok(input
.lines()
.map(|l| {
!r1.is_match(l).unwrap_or(false)
&& r2.is_match(l).unwrap_or(false)
&& r3.is_match(l).unwrap_or(false)
})
.map(|m| if m { 1 } else { 0 })
.sum::<u32>())
}
}
impl aoclib::Solvable<&str, u32> for PartTwo {
fn solve(input: &str) -> aoclib::Solution<u32> {
let r1 = Regex::new(r"(..).*\1")?;
let r2 = Regex::new(r"(.).\1")?;
Ok(input
.lines()
.map(|l| r1.is_match(l).unwrap_or(false) && r2.is_match(l).unwrap_or(false))
.map(|m| if m { 1 } else { 0 })
.sum::<u32>())
}
}