Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
31
Task/Balanced-brackets/SETL/balanced-brackets.setl
Normal file
31
Task/Balanced-brackets/SETL/balanced-brackets.setl
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
program balanced_brackets;
|
||||
setrandom(0);
|
||||
|
||||
loop for length in [1..10] do
|
||||
s := generate length;
|
||||
print(balanced s, s);
|
||||
end loop;
|
||||
|
||||
op generate(n);
|
||||
s := "["*n + "]"*n;
|
||||
loop for i in [n*2, n*2-1..2] do
|
||||
j := 1 + random(i - 1);
|
||||
[s(i), s(j)] := [s(j), s(i)];
|
||||
end loop;
|
||||
return s;
|
||||
end op;
|
||||
|
||||
op balanced(s);
|
||||
depth := 0;
|
||||
loop for c in s do
|
||||
case c of
|
||||
("["):
|
||||
depth +:= 1;
|
||||
("]"):
|
||||
depth -:= 1;
|
||||
if depth<0 then return false; end if;
|
||||
end case;
|
||||
end loop;
|
||||
return depth = 0;
|
||||
end op;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue