-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlib.rs
36 lines (32 loc) · 774 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
34
35
36
pub struct PartOne;
pub struct PartTwo;
impl aoclib::Solvable<&str, u32> for PartOne {
fn solve(input: &str) -> aoclib::Solution<u32> {
let v = input
.chars()
.filter_map(|c| c.to_string().parse::<u8>().ok())
.collect::<Vec<u8>>();
let mut sum: u32 = 0;
for (i, n) in v.iter().enumerate() {
if n == v.get((i + 1) % v.len()).unwrap() {
sum += *n as u32;
}
}
Ok(sum)
}
}
impl aoclib::Solvable<&str, u32> for PartTwo {
fn solve(input: &str) -> aoclib::Solution<u32> {
let v = input
.chars()
.filter_map(|c| c.to_string().parse::<u8>().ok())
.collect::<Vec<u8>>();
let mut sum: u32 = 0;
for (i, n) in v.iter().enumerate() {
if n == v.get((i + v.len() / 2) % v.len()).unwrap() {
sum += *n as u32;
}
}
Ok(sum)
}
}