Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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(["","[]", "[][]", "[[][]]", "][",
"][][", "[]][[]", "[][][][][][][][][][]",
"[[[[[[[]]]]]]]", "[[[[[[[]]]]]]",
"[][[]][]","[[][]][]", "[][][[]][]"]).

View 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.