struct TopographicalMap {
cells: Vec<Vec<u8>>,
}
Expand description
Represent the map as a list of lists of cells. Most of the business logic for today’s puzzles are functions implemented on this struct.
Fields§
§cells: Vec<Vec<u8>>
Implementations§
source§impl TopographicalMap
impl TopographicalMap
sourcefn trailheads(&self) -> Vec<(usize, usize)>
fn trailheads(&self) -> Vec<(usize, usize)>
Find all the lowest points (height 0
)
sourcefn get(&self, (r, c): (usize, usize)) -> Option<u8>
fn get(&self, (r, c): (usize, usize)) -> Option<u8>
Get the value at particular coordinates. Returns None
if the coordinates are outside the bounds of the grid.
sourcefn adjacent(&self, (r, c): (usize, usize)) -> Vec<((usize, usize), u8)>
fn adjacent(&self, (r, c): (usize, usize)) -> Vec<((usize, usize), u8)>
Return a list of coordinates and heights of orthogonally adjacent cells. Typically, there are four, but cells
on the edge of the TopographicalMap
will return fewer.
sourcefn get_peaks(&self, cell: (usize, usize)) -> Vec<(usize, usize)>
fn get_peaks(&self, cell: (usize, usize)) -> Vec<(usize, usize)>
Find all valid routes to any peak (height 9
) from a given trailhead, returning the coordinates of those peaks.
Where there are multiple routes up a peak they will be duplicates. A route is valid if each step increases by
1 unit.
sourcefn score_trailhead(&self, trailhead: (usize, usize)) -> usize
fn score_trailhead(&self, trailhead: (usize, usize)) -> usize
Get the count of unique peaks reachable from a given trailhead
sourcefn total_score(&self) -> usize
fn total_score(&self) -> usize
Solves part 1 - the sum of [self.score_trailhead
] over all trailheads.
sourcefn rate_trailhead(&self, cell: (usize, usize)) -> usize
fn rate_trailhead(&self, cell: (usize, usize)) -> usize
Get the count of valid trails to peaks from a given trailhead
sourcefn total_rating(&self) -> usize
fn total_rating(&self) -> usize
Solves part 2 - the sum of [self.rate_trailhead
] over all trailheads.
Trait Implementations§
source§impl Debug for TopographicalMap
impl Debug for TopographicalMap
source§impl PartialEq for TopographicalMap
impl PartialEq for TopographicalMap
impl Eq for TopographicalMap
impl StructuralPartialEq for TopographicalMap
Auto Trait Implementations§
impl Freeze for TopographicalMap
impl RefUnwindSafe for TopographicalMap
impl Send for TopographicalMap
impl Sync for TopographicalMap
impl Unpin for TopographicalMap
impl UnwindSafe for TopographicalMap
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.