-
Notifications
You must be signed in to change notification settings - Fork 0
/
part1.rs
47 lines (37 loc) · 983 Bytes
/
part1.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
45
46
47
use super::*;
pub type OutputType = usize;
pub fn dedup(data: &mut InputType) -> bool {
let mut res: InputType = InputType::new();
for cc in data.iter() {
if res.is_empty() {
res.push_back(*cc);
continue;
}
let prev = *res.back().unwrap();
if *cc != prev && cc.to_ascii_lowercase() == prev.to_ascii_lowercase() {
res.pop_back();
} else {
res.push_back(*cc);
}
}
let retval = !(data.len() == res.len());
*data = res;
retval
}
pub fn solve(input: &InputType) -> (OutputType, InputType) {
let mut data = input.to_owned();
while dedup(&mut data) {}
(data.len(), data)
}
#[cfg(test)]
mod tests {
use super::*;
fn solve_example(name: &str) -> OutputType {
let input = parse_input(name, false);
solve(&input).0
}
#[test]
fn examples() {
assert_eq!(solve_example("example1"), "dabCBAcaDA".len());
}
}