Balanced brackets: Difference between revisions
Content added Content deleted
(Add Ecstasy example) |
|||
Line 4,473: | Line 4,473: | ||
^</pre> |
^</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq.''' |
|||
<syntaxhighlight lang=jq> |
|||
def balanced: |
|||
if length==0 then true |
|||
elif .[:1] == "]" then false |
|||
else test("[[][]]") and (sub("[[][]]"; "") | balanced) |
|||
end; |
|||
def task($n): |
|||
if $n%2 == 1 then null |
|||
else |
|||
(reduce range(0; $n) as $i (""; |
|||
. + (if psrb then "[" else "]" end) )) |
|||
| "\(.): \(balanced)" |
|||
end; |
|||
task(0), |
|||
task(2), |
|||
(range(0;10) | task(4)) |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
: true |
|||
[]: true |
|||
]][]: false |
|||
[[[[: false |
|||
[[[[: false |
|||
[][]: true |
|||
][][: false |
|||
[]]]: false |
|||
]]]]: false |
|||
]]][: false |
|||
[]][: false |
|||
][[]: false |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang="julia">using Printf |
<syntaxhighlight lang="julia">using Printf |