2018-6: What's Your Angle?
XML elements are denoted with content enclosed in beginning and ending tags. The tags themselves are enclosed in left and right angle brackets <
and >
. The only valid occurrences of angle brackets are as a part of beginning or ending tags.
For example, the following is valid
<name><first>Drake</first><last>Mallard</last></name>
Whereas the following is not valid XML
<math><relation>2<3</relation></math>
One easy validation is to check that the angle brackets are properly balanced – all left angle brackets <
must be "closed" with right angle brackets >
before another occurrence of a left angle bracket.
Write an APL function that, given a character scalar or vector representing some XML, returns 1 if the angle brackets are properly balanced and 0 if not.
Examples:
(your_function) '<name><first>Drake</first><last>Mallard</last></name>'
1
(your_function) '<math><relation>2<3</relation></math>'
0
(your_function) '' ⍝ an empty vector is balanced
1
(your_function) '>stuff<>/stuff<'
0
(your_function) '<'
0
your_function ←
Solutions

