Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Balanced-brackets/Jq/balanced-brackets-1.jq
Normal file
33
Task/Balanced-brackets/Jq/balanced-brackets-1.jq
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
< /dev/random tr -cd '0-9' | fold -w 1 | jq -Mcnr '
|
||||
|
||||
# Output: a PRN in range(0;$n) where $n is .
|
||||
def prn:
|
||||
if . == 1 then 0
|
||||
else . as $n
|
||||
| (($n-1)|tostring|length) as $w
|
||||
| [limit($w; inputs)] | join("") | tonumber
|
||||
| if . < $n then . else ($n | prn) end
|
||||
end;
|
||||
|
||||
def prb: 2 | prn == 0;
|
||||
|
||||
def balanced:
|
||||
{array: explode, parity: 0}
|
||||
| until( .result | type == "boolean";
|
||||
if .array == [] then .result = (.parity == 0)
|
||||
else .parity += (.array[0] | if . == 91 then 1 else -1 end)
|
||||
| if .parity < 0 then .result = false
|
||||
else .array |= .[1:]
|
||||
end
|
||||
end ).result ;
|
||||
|
||||
def task($n):
|
||||
if $n%2 == 1 then null
|
||||
else [ (range(0; $n) | if prb then "[" else "]" end) // ""]
|
||||
| add
|
||||
| "\(.): \(balanced)"
|
||||
end;
|
||||
|
||||
task(0),
|
||||
task(2),
|
||||
(range(0;10) | task(4))
|
||||
19
Task/Balanced-brackets/Jq/balanced-brackets-2.jq
Normal file
19
Task/Balanced-brackets/Jq/balanced-brackets-2.jq
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
def prb: (now|tostring[-1:] | tonumber) % 2 == 0;
|
||||
|
||||
def balanced:
|
||||
if length==0 then true
|
||||
elif .[:1] == "]" then false
|
||||
else test("[[][]]") and (gsub("[[][]]"; "") | balanced)
|
||||
end;
|
||||
|
||||
def task($n):
|
||||
if $n%2 == 1 then null
|
||||
else
|
||||
(reduce range(0; $n) as $i ("";
|
||||
. + (if prb then "[" else "]" end) ))
|
||||
| "\(.): \(balanced)"
|
||||
end;
|
||||
|
||||
task(0),
|
||||
task(2),
|
||||
(range(0;10) | task(4))
|
||||
Loading…
Add table
Add a link
Reference in a new issue