You should write a program or function which receives a string representing an ASCII art as input and outputs or returns the number of endpoints in the input.
The input will consist of the characters space - | +
(with 0, 2, 2 and 4 endpoints respectively) and linebreaks. E.g.:
-|++-
+
Two adjacent characters are connected and hence lose 1 endpoint each in the following cases:
-- -+ +- | | + + ++
| + | +
The first example has
2+2+2+2+1+
3 = 12
endpoints.
Input
- Input will be a string consisting of the characters space,
-
,|
,+
and newline. - Input length can be 0 length and any input matching the above description is valid (in regex input is
[ -+|\n]*
). - Trailing newline is optional.
Output
- A single non-negative integer, the number of endpoints.
Examples
Outputs are after the last row of their inputs.
+
4
-|++-
+
12
+--+
| |
+--+
8
| |
+--+-- |||
12
--++
|||--
10
<empty input>
0
|
|
2
--
++--
++
--+
+++ ||
----
30
This is code golf so the shortest entry wins.