Balanced brackets: Difference between revisions

→‎{{header|Factor}}: Remove an incorrect solution: it fails to check the negative balance, and doesn't implement the random string generation.
m (→‎{{header|Perl}}: use Regexp::Common subroutine interface, works with recent versions of Perl)
(→‎{{header|Factor}}: Remove an incorrect solution: it fails to check the negative balance, and doesn't implement the random string generation.)
Line 3,267:
readln
balanced</syntaxhighlight>
 
Some more idiomatic solution might be as follows:
 
<syntaxhighlight lang="factor">USING: io formatting locals kernel math sequences unicode.case ;
IN: balanced-brackets
 
: map-braces ( -- qout )
[
{
{ "[" [ drop 1 ] }
{ "]" [ drop -1 ] }
[ drop 0 ]
} case
]
;
 
: balanced? ( str -- ? )
map-braces map sum 0 =
;
 
"[1+2*[3+4*[5+6]-3]*4-[3*[3+3]]]" balanced?
-- Data stack:
t
</syntaxhighlight>
 
=={{header|Fantom}}==
8

edits