Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
12
Task/Balanced-brackets/Nu/balanced-brackets.nu
Normal file
12
Task/Balanced-brackets/Nu/balanced-brackets.nu
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def gen_brackets [n: int] { 1..$in | each {["[" "]"]} | flatten | shuffle | str join }
|
||||
|
||||
def check_brackets [] {
|
||||
split chars | reduce --fold 0 {|x, d|
|
||||
if ($d < 0) {-1} else {
|
||||
$d + (if ($x == "[") {1} else {-1})
|
||||
}
|
||||
} | $in > -1
|
||||
}
|
||||
|
||||
|
||||
1..10 | each {gen_brackets $in | {brackets: $in, valid: ($in | check_brackets)}} | print
|
||||
Loading…
Add table
Add a link
Reference in a new issue