Jelly, 5 bytes
VeMḂ$
Monadic function expecting a string. Inputs with leading !
s cause a 1
to be printed to STDOUT along the way, so the TIO link I give is a test harness that prints the input-output pairs beneath the first line of output.
###How?
How?
VeMḂ$ - Monadic link: string
V - eval the string
- the implicit input of 0 causes !...! to evaluate to 1 (which gets printed),
- the result is the evaluation of the rest: "0"=0; "0!"=1; "1"=1; "1!"=1; ...
e - exists in?
$ - last two links as a monad:
M - Maximal indexes - the "0" and "1" characters are greater than "!",
- so this results in a list of one item [i] where
- i is the 1-based index of the 0 or 1 character.
Ḃ - %2 (vectorises) - [i%2], so a 0 if we need to logically negate and a 1 if not
- hence we check equality with e rather than inequality.