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,22 @@
let isBalanced str =
let rec loop count = function
| ']'::_ when count = 0 -> false
| '['::xs -> loop (count+1) xs
| ']'::xs -> loop (count-1) xs
| [] -> count = 0
| _::_ -> false
str |> Seq.toList |> loop 0
let shuffle arr =
let rnd = new System.Random()
Array.sortBy (fun _ -> rnd.Next()) arr
let generate n =
new string( String.replicate n "[]" |> Array.ofSeq |> shuffle )
for n in 1..10 do
let s = generate n
printfn "\"%s\" is balanced: %b" s (isBalanced s)