Day 16
This commit is contained in:
parent
7ff46b8f99
commit
965bdca334
3 changed files with 210 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ use std::fmt::Display;
|
|||
|
||||
use itertools::Itertools;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum Direction {
|
||||
North,
|
||||
South,
|
||||
|
|
@ -27,6 +27,24 @@ impl Direction {
|
|||
pub fn is_parallel(self, other: Self) -> bool {
|
||||
self == other || self == other.opposite()
|
||||
}
|
||||
|
||||
pub fn clockwise(self) -> Self {
|
||||
match self {
|
||||
Self::North => Self::East,
|
||||
Self::East => Self::South,
|
||||
Self::South => Self::West,
|
||||
Self::West => Self::North,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn counterclockwise(self) -> Self {
|
||||
match self {
|
||||
Self::North => Self::West,
|
||||
Self::West => Self::South,
|
||||
Self::South => Self::East,
|
||||
Self::East => Self::North,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -134,6 +152,11 @@ where
|
|||
pub fn enumerate(&self) -> impl Iterator<Item = (usize, usize, &T)> {
|
||||
self.coordinates().map(|(x, y)| (x, y, &self.map[y][x]))
|
||||
}
|
||||
|
||||
pub fn map<U: Copy, F: Fn(&T) -> U>(&self, f: F) -> Map<U> {
|
||||
let v = self.map.iter().map(|row| row.iter().map(|e| f(e)).collect()).collect();
|
||||
Map::<U>::from_2d_vec(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Display for Map<T>
|
||||
|
|
|
|||
Reference in a new issue