Today’s problem has us using path finding to determine the quality of hiking trails.
The twist for today, may just come from me instead of the problem.
As per use you can find the solutions discussed below on my github.
Part A
The Problem
We are given a topographic map of some mountain.
It is our job to grade trailhead.
The score of a trailhead is the number of peaks (9) one can reach from the (0) incrementing by one on each step.
The Solution
My first pass solution was to find each trailhead then walk to each peak and count what I see.
This was easy enough to do recursively.
For each direction I would try to walk, and when I found a peak:
This, however, counted far two many peaks.
I then realized that I was counting the number of routes to each 9 not the nines that I could see.
So, I retro fitted a hash set into the mix to count unit peaks per trailhead.
This easily worked.
The Full Solution
Part B
The Twist
The twist today was rather funny as I had done it on accident.
The twist was to count the number of paths to the peaks.
So, I simply switched the code back to my erroneous part A code.
How we Adapt
There’s no source here as there is a flag above (around line 43) that will control part A from B.
Call it luck or foresight, but don’t call it bad software.