-
Notifications
You must be signed in to change notification settings - Fork 0
/
05.rs
44 lines (33 loc) · 972 Bytes
/
05.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
34
35
36
37
38
39
40
41
42
43
44
#![feature(test)]
use itertools::Itertools;
type Input = Vec<String>;
fn setup(input: &str) -> Input {
input.trim().lines().map(Into::into).collect()
}
fn part1(input: &Input) -> usize {
input
.iter()
.filter(|s| {
let r1 = s
.chars()
.filter(|c| "aeiou".contains(c.to_ascii_lowercase()))
.count()
>= 3;
let r2 = s.chars().tuple_windows().any(|(a, b)| a == b);
let r3 = ["ab", "cd", "pq", "xy"].into_iter().all(|x| !s.contains(x));
r1 && r2 && r3
})
.count()
}
fn part2(input: &Input) -> usize {
input
.iter()
.filter(|s| {
let r1 =
(0..s.len() - 1).any(|i| (i + 2..s.len() - 1).any(|j| s[i..i + 2] == s[j..j + 2]));
let r2 = s.chars().tuple_windows().any(|(a, _, b)| a == b);
r1 && r2
})
.count()
}
aoc::main!(2015, 5);