#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Direction {
North,
East,
West,
South,
}
fn dir_reduc(arr: &[Direction]) -> Vec<Direction> {
let mut v: Vec<Direction> = vec![];
for i in arr {
match (i, v.last()) {
(&Direction::North, Some(&Direction::South))
| (&Direction::South, Some(&Direction::North))
| (&Direction::East, Some(&Direction::West))
| (&Direction::West, Some(&Direction::East)) => {
v.pop();
continue;
},
(_, _) => v.push(*i),
};
};
v
}
fn test() {
use Direction::{self, *};
let a = [North, South, South, East, West, North, West];
assert_eq!(dir_reduc(&a), [West]);
let a = [North, West, South, East];
assert_eq!(dir_reduc(&a), [North, West, South, East]);
}
test()