Balanced brackets: Difference between revisions

Content added Content deleted
(RPL version)
Line 6,707: Line 6,707:
bracket string [[]] is ok.
bracket string [[]] is ok.
bracket string ]]]][]]]]]]]]] is not ok.
bracket string ]]]][]]]]]]]]] is not ok.
</pre>

=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
<syntaxhighlight lang="RPL">
'BALBKT'
1 OVER SIZE
WHILE DUP2 * 0 > REPEAT
3 PICK OVER DUP SUB
IF "[]" SWAP POS THEN
LAST 2 * 3 -
ROT + SWAP
END
1 -
END
DROP
1 SAME "" "Not " IFTE
"OK" +
'ASSERT'
≪ "" BALBKT " → " SWAP + +
"[]" BALBKT " → " SWAP + +
"[][]" BALBKT " → " SWAP + +
"[[][]]" BALBKT " → " SWAP + +
"][" BALBKT " → " SWAP + +
"][][" BALBKT " → " SWAP + +
"[]][[]" BALBKT " → " SWAP + +
</syntaxhighlight>
{{out}}
<pre>

ASSERT
" → OK"
"[] → OK"
"[][] → OK"
"[[][]] → OK"
"][ → Not OK"
"][][ → Not OK"
"[]][[] → Not OK"
</pre>
</pre>