Day 18
This commit is contained in:
parent
b9da7b7cf6
commit
187e3c8b07
2 changed files with 15 additions and 2 deletions
|
|
@ -154,9 +154,20 @@ where
|
|||
}
|
||||
|
||||
pub fn map<U: Copy, F: Fn(&T) -> U>(&self, f: F) -> World<U> {
|
||||
let v = self.map.iter().map(|row| row.iter().map(|e| f(e)).collect()).collect();
|
||||
let v = self
|
||||
.map
|
||||
.iter()
|
||||
.map(|row| row.iter().map(|e| f(e)).collect())
|
||||
.collect();
|
||||
World::<U>::from_2d_vec(v)
|
||||
}
|
||||
|
||||
pub fn adjacent_locations(&self, x: usize, y: usize) -> Vec<(usize, usize)> {
|
||||
Direction::all_variants()
|
||||
.into_iter()
|
||||
.filter_map(|d| self.travel(x, y, d))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Display for World<T>
|
||||
|
|
|
|||
Reference in a new issue