13
1
In mountaineering terminology, a "14er" is any mountain with an elevation of 14 000 feet or more. However, there is another distinction. For a peak to count as a 14er, it must also have a "geographic prominence" of 300 or more feet. This means that to move from one 14er to another, you must first descend at least 300 feet before rising again. Take this example. Line 1 counts as 14 000 feet, and each line counts as 100 feet.
/\__/\
/ \
/ \
Now, both of these peaks have enough elevation to count, but there isn't enough drop in elevation between them to count as two separate peaks. Therefore, one of these counts as a 14er, and the other one is just a "partial peak". Here is an example where the two peaks count as two separate 14er:
/\ /\
/ \ / \
/ \/ \
/ \
There can also be a partial peak on the decline between two 14ers. Here's a slightly modified version of the last mountain range:
/\ /\
/ \/\ / \
/ \/ \
/ \
This mountain range also counts as two 14ers.
You must write a program or function that takes an ascii-art representation of a mountain range, and return how many 14ers are in the range. You can take input in whatever format is most convenient for you, be it 2D array of characters, a string with newline, or a string with some other delimiter. You can assume that all inputs will only contain the characters /\_
, and that the length of each line will be the same (including trailing spaces). You can also assume that the mountain range starts on the bottom left corner with either a /
or a _
.
If the last section of a mountain is not on the bottom line, you can assume that the mountain only decreases after that, e.g.
/
/
/
Counts as a single 14er.
You do not have to handle invalid mountain ranges.
Here is some sample I/O:
/\___/\_
/ \ /\
/ \ / \
_/\/ \/ \
/ \
/ \
/ \_
2
/\ /\
/\ / \ /
/\ / \ / \/
/ \ / \ /
/ \/ \/
4
/\
_/\__/ \
/ \
1
/\
/ \ /\
/ \_/ \
/ \
/ \
/ \
/ \
1
/\
/\_/\ / \_
/ \ / \ /\
/ \/ \ /
/ \_/
/
3
So the starting line counts as 14,000 feet? – R. Kap – 2016-04-23T06:42:26.367
@R.Kap Yes, I believe that's correct, assuming you mean the bottom line when you say starting line. – Alex A. – 2016-04-23T06:43:43.177
And you always begin with a 14er? – R. Kap – 2016-04-23T06:45:53.110
Is a trailing newline admissible? – mIllIbyte – 2016-04-23T09:17:18.343
Related: http://codegolf.stackexchange.com/questions/68967/how-many-peaks-in-my-mountain-range
– Neil – 2016-04-23T09:32:46.9471I think you should mention somewhere that a
_
counts as 100 feet lower than a slash on the same line. At least that's what your last test case suggests. – Martin Ender – 2016-04-23T09:50:06.813I can feel a Retina answer coming... – Luis Mendo – 2016-04-23T10:34:23.560
3The spec seems thin... can we have a flat peat like
/ / / _ \ \ \
? Also, I suppose that the highest point in the input should always be counted as a peak but this is not explicitly specified; one could start at a lower peak and end up with a different count. – feersum – 2016-04-23T11:06:48.7302Will it always be continous? Will it have at most one nonspace character for each column? – Leaky Nun – 2016-04-23T11:22:15.287