A bird flying high above a mountain range is able to estimate the height of the highest peak.
Can you?
Height=3
This challenge comes from dinglemouse at CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Discussion (4)
A TypeScript version using reduces and maps to avoid too much mutation.
The main loop early exits if possible (if there are no hills left), otherwise it erodes the mountainscape by one hill. The
starPattern
array determines how this erosion happens, and it seems that the challenge uses up-down-left-right-dot.Tested on Kata in its JS form.
Note that on there the mountains are defined using something like this:
Clojure solution:
Not as elegant as I hoped. Debugging output included.
Swift Solution:
Output:
Definitely feel like I'm going a little heavy on the looping, but I was having a hard time visualizing how I could map the increasing elevations without keeping a reference copy of the array to make sure I wasn't just blowing through everything on each pass.... Any suggestions for improvements would be appreciated!