31
3
You should write a program or function which receives a string representing an ascii-art polygon as input and outputs ot returns the area of the polygon.
The input is a string consisting of the characters _ / \ L V space
and newline
defining a simple polygon (which means no extra segments, no self-touch and no self-intersect).
The area of a single character cell is 2
_
splits the cell into sizes0
and2
\
splits the cell into sizes1
and1
/
splits the cell into sizes1
and1
L
splits the cell into sizes0
and2
V
splits the cell into sizes1
and1
(The two sides of theV
will always be on the same side of the polygon so they are treated together in the listing.)
Every character connects the two corners of its character cell which you expect (e.g. top left and top right in case of V
).
An example with area of 7 (1+2+1
in the second row and 1+1+1
in the third one):
_
/ \
V\/
Input
- Input will form a rectangle, i.e. there will be the same number of characters between newlines.
- There can be extra whitespace on any side of the polygon.
- Trailing newline is optional.
Output
- A single positive integer, the area of the polygon.
Examples
Outputs are after the last row of their inputs.
_
V
1
/L
\/
3
/VV\
L /
L/
14
____/\
\ /
/\/ /
\____/
32
/V\
/ \__
\ /
/\/ /V
L____/
45
This is code-golf so the shortest entry wins.
your third example should be 14 – Optimizer – 2015-04-27T11:00:12.947
@Optimizer Thanks, corrected. – randomra – 2015-04-27T11:58:28.967
Is the lack of
^
intentionally? – RobAu – 2015-04-28T11:41:40.480@RobAu Yes, that doesn't look good enough. – randomra – 2015-04-28T12:07:15.303