let rec f=function|'!'::t->1-f t|'0'::[]->0|_->1
///////////////////////////////////////
let test (input,expected) =
let result = input |> Seq.toList |> f
if result = expected then
printfn "%s = %d" input result
else
printfn "Error at %s" input
[
("0", 0)
("1", 1)
("0!", 1)
("1!", 1)
("!0", 1)
("!1", 0)
("!0!", 0)
("!1!", 0)
("0!!", 1)
("1!!", 1)
("!!0", 0)
("!!1", 1)
("!0!!", 0)
("!!!1", 0)
("!!!0!!!!", 0)
("!!!1!!!!", 0)
] |> Seq.iter test