Jump to content

Balanced brackets: Difference between revisions

Add APL
m (→‎{{header|XBasic}}: Regularize non-standard header markup)
(Add APL)
Line 598:
input is: []line 1:2 missing NEWLINE at ']'
</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
 
These are a function to generate a random string of N brackets of each type,
and a function to check whether a given string of brackets is balanced.
 
<lang APL>gen ← (⊂+?+)⍨ ⌷ ('[]'/⍨⊢)
bal ← ((|≡⊢)+\ ∧ 0=+/)(+⌿1 ¯1×[1]'[]'∘.=⊢)</lang>
 
Sample run for 0..N..10:
 
<lang APL> ↑{br←gen ⍵ ⋄ br,': ',(1+bal br)⊃'Bad' 'Good'}¨0,⍳10
: Good
[]: Good
][][: Bad
[][[]]: Good
[]]][[][: Bad
][][[[[]]]: Bad
][][][][][[]: Bad
][[[][[][]][]]: Bad
[[][[]]][[[[]]]]: Good
[[[]][[[[][]][]]]]: Good
]][][][][[][][]][[[]: Bad</lang>
 
=={{header|AppleScript}}==
2,124

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.