2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,7 @@
fun isBalanced s = checkBrackets 0 (String.explode s)
and checkBrackets 0 [] = true
| checkBrackets _ [] = false
| checkBrackets ~1 _ = false
| checkBrackets counter (#"["::rest) = checkBrackets (counter + 1) rest
| checkBrackets counter (#"]"::rest) = checkBrackets (counter - 1) rest
| checkBrackets counter (_::rest) = checkBrackets counter rest

View file

@ -0,0 +1,11 @@
val () =
List.app print
(List.map
(* Turn `true' and `false' to `OK' and `NOT OK' respectively *)
(fn s => if isBalanced s
then s ^ "\t\tOK\n"
else s ^ "\t\tNOT OK\n"
)
(* A set of strings to test *)
["", "[]", "[][]", "[[][]]", "][", "][][", "[]][[]"]
)