Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Balanced-brackets/Picat/balanced-brackets-1.picat
Normal file
25
Task/Balanced-brackets/Picat/balanced-brackets-1.picat
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
go1 ?=>
|
||||
tests(Tests),
|
||||
member(Test,Tests),
|
||||
printf("%s: ", Test),
|
||||
( balanced_brackets(Test) ->
|
||||
println("OK")
|
||||
;
|
||||
println("NOT OK")
|
||||
),
|
||||
fail,
|
||||
nl.
|
||||
go1 => true.
|
||||
|
||||
% Check if a string of [] is balanced
|
||||
balanced_brackets(B) =>
|
||||
C = 0,
|
||||
foreach(I in 1..B.length, C >= 0)
|
||||
C:= C + cond(B[I] = '[', 1, -1)
|
||||
end,
|
||||
C == 0.
|
||||
|
||||
tests(["","[]", "[][]", "[[][]]", "][",
|
||||
"][][", "[]][[]", "[][][][][][][][][][]",
|
||||
"[[[[[[[]]]]]]]", "[[[[[[[]]]]]]",
|
||||
"[][[]][]","[[][]][]", "[][][[]][]"]).
|
||||
15
Task/Balanced-brackets/Picat/balanced-brackets-2.picat
Normal file
15
Task/Balanced-brackets/Picat/balanced-brackets-2.picat
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
go_dcg ?=>
|
||||
tests(Tests),
|
||||
foreach(Test in Tests)
|
||||
printf("%s: ", Test),
|
||||
if balanced(Test,[]) then
|
||||
println("OK")
|
||||
else
|
||||
println("NOT OK")
|
||||
end
|
||||
end,
|
||||
nl.
|
||||
go_dcg => true.
|
||||
|
||||
balanced --> "".
|
||||
balanced --> "[", balanced, "]", balanced.
|
||||
Loading…
Add table
Add a link
Reference in a new issue