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,13 @@
(* Generate open/close events. *)
gen[n_] := RandomSample[Table[{1, -1}, {n}] // Flatten]
(* Check balance. *)
check[lst_] := And @@ (# >= 0 & /@ Accumulate[lst])
(* Do task for string with n opening and n closing brackets. *)
doString[n_] := (
lst = gen[n];
str = StringJoin[lst /. {1 -> "[", -1 -> "]"}];
Print[str <> If[match[lst, 0],
" is balanced.",
" is not balanced."]])