Anonymous user
Balanced brackets: Difference between revisions
→{{header|D}}
(→{{header|Tcl}}: Marked incomplete as strings are not generated) |
|||
Line 11:
=={{header|D}}==
{{incomplete|D|Strings are not generated.}}
<lang d>import std.stdio, std.algorithm, std.string, std.range, std.random, std.conv;
auto generate(int n) {
return text(map!((i){ return "[]"[uniform(0,2)]; })(iota(n)));
}
void main() {
foreach (
auto s = generate(i);
writefln("%-15s is%s
s.balancedParens('[', ']') ? "" : " not");
}
}</lang>
Output:
<pre>"" is balanced
"[
"
"
"][][" is not balanced
"][][]" is not balanced
"[
"[]][[[]" is not balanced
"][][][[]" is not balanced
"][]][][[]" is not balanced
"[]][[]][[]" is not balanced
"][[]]][]]][" is not balanced
"[[]][[[[]]]]" is balanced
"[[]][][]]]][[" is not balanced</pre>
=={{header|Perl 6}}==
|