;; These could be improved into a macro but want readability(defncheck-left[rowcolmountains]"Checks the cell to the left"(if(and(>=(-col1)0)(.equals((mountainsrow)(-col1))"^"))truefalse))(defncheck-up[rowcolmountains]"Checks the cell above"(if(and(>=(-row1)0)(.equals((mountains(-row1))col)"^"))truefalse))(defncheck-right[rowcolmountains]"Checks the cell to the right"(if(and(<(+col1)(count(mountainsrow)))(.equals((mountainsrow)(+col1))"^"))truefalse))(defncheck-down[rowcolmountains]"Checks the cell below"(if(and(<(+row1)(countmountains))(.equals((mountains(+row1))col)"^"))truefalse))(defnwill-erode?[rowcolmountains]"Returns true if the current cell is not completely surrounded by mountains"(not(and(check-leftrowcolmountains)(check-uprowcolmountains)(check-rightrowcolmountains)(check-downrowcolmountains))))(defnerode-mountains[mountainserrosion-symbol]"Erodes the mountains once"(into[](map-indexed(fn[row-indexrow](into[](map-indexed(fn[col-indexcol](if(and(.equalscol"^")(will-erode?row-indexcol-indexmountains))errosion-symbolcol))row)))mountains)))(defnfully-eroded?[mountains](nil?(first(filter#(.equals"^"%)(flattenmountains)))))(defnpeak-height[mountains]"Get the peak height (according to a fictional bird)"(loop[times0mtsmountains](if-not(fully-eroded?mts)(recur(+times1)(erode-mountainsmtstimes))times)))(defmountains[["^""^""^""^""^""^"" "" "" "" "" "" "" "" "][" ""^""^""^""^""^""^""^""^"" "" "" "" "" "][" "" ""^""^""^""^""^""^""^"" "" "" "" "" "][" "" ""^""^""^""^""^"" "" "" "" "" "" "" "][" "" ""^""^""^""^""^""^""^""^""^""^""^"" "][" "" ""^""^""^""^""^""^"" "" "" "" "" "" "][" "" ""^""^""^""^"" "" "" "" "" "" "" "" "]])(peak-heightmountains);; 3
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Clojure solution: