Grime, 16 1414 11 bytes
Thanks to Zgarb for saving 25 bytes.
e`.^-d\0v#|e`s\0v#|!..
The e
tells Grime to try and match the entire input and print 0
or 1
depending on whether that's possible.
The |!
is effectively a "neither" operator, because x|!y
is shorthand for (x|y)!
. So we make sure that the input neither contains a zero preceded by a non-digitsymbol nor is a string of only two characters ([]
).
A note about the second half: .P#
matches any charactera rectangle that contains at least one match of P
. However, in our case dP
matches any digit andconsists of both -s
is boolean differenceand (so we require it to match one character, but disallow that character to be a digit). The only issue is\0
so that would normally require parentheses: -(s\0)#
has lower(because the precedence than concatenation so we'd have to add parenthesesof #
is too high). But Grime has a really niftyneat feature where you can changemodify the operator precedence. of operators with ^-
is likeand -v
but with higher precedence than any other operator, which is the same as wrapping it and its arguments in parentheses and saves a byte. Likewise the containment operatorSo by using #v#
has too high precedence and would require parentheses around the stuff in front of it, but we can lower its precedence with v#
to's precedence so that it's lower than that of any other operator (including concatenation), which lets us save anothera byte on the parentheses.