Skip to main content
deleted 201 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Grime, 16 1414 11 bytes

Thanks to Zgarb for saving 25 bytes.

e`.^-d\0v#|e`s\0v#|!..

Try it online!Try it online!

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.

Grime, 16 14 bytes

Thanks to Zgarb for saving 2 bytes.

e`.^-d\0v#|!..

Try it online!

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-digit nor is a string of only two characters ([]).

A note about the second half: . matches any character, d matches any digit and - is boolean difference (so we require it to match one character, but disallow that character to be a digit). The only issue is that - has lower precedence than concatenation so we'd have to add parentheses. But Grime has a really nifty feature where you can change the operator precedence. ^- is like - 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 operator # has too high precedence and would require parentheses around the stuff in front of it, but we can lower its precedence with v to save another byte.

Grime, 16 14 11 bytes

Thanks to Zgarb for saving 5 bytes.

e`s\0v#|!..

Try it online!

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 symbol nor is a string of only two characters ([]).

A note about the second half: P# matches a rectangle that contains at least one match of P. However, in our case P consists of both s and \0 so that would normally require parentheses: (s\0)# (because the precedence of # is too high). But Grime has a really neat feature where you can modify the precedence of operators with ^ and v. So by using v# we lower #'s precedence so that it's lower than that of any other operator (including concatenation), which lets us save a byte on the parentheses.

added 47 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Grime, 1616 14 bytes

Thanks to Zgarb for saving 2 bytes.

e`..|!.*.^-d\0d\0v#|!.*.

Try it online!Try it online!

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 is neither contains a zero preceded by a non-digit nor is a string of only two characters ([]) nor contains a zero preceded by a non-digit.

A note about the second half: . matches any character, d matches any digit and - is boolean difference (so we require it to match one character, but disallow that character to be a digit). The only issue is that - has lower precedence than concatenation so we'd have to add parentheses. But Grime has a really nifty feature where you can change the operator precedence. ^- is like - 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 operator # has too high precedence and would require parentheses around the stuff in front of it, but we can lower its precedence with v to save another byte.

Grime, 16 bytes

e`..|!.*.^-d\0.*

Try it online!

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 is neither a string of only two characters ([]) nor contains a zero preceded by a non-digit.

A note about the second half: . matches any character, d matches any digit and - is boolean difference (so we require it to match one character, but disallow that character to be a digit). The only issue is that - has lower precedence than concatenation so we'd have to add parentheses. But Grime has a really nifty feature where you can change the operator precedence. ^- is like - but with higher precedence than any other operator, which is the same as wrapping it and its arguments in parentheses and saves a byte.

Grime, 16 14 bytes

Thanks to Zgarb for saving 2 bytes.

e`.^-d\0v#|!..

Try it online!

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-digit nor is a string of only two characters ([]).

A note about the second half: . matches any character, d matches any digit and - is boolean difference (so we require it to match one character, but disallow that character to be a digit). The only issue is that - has lower precedence than concatenation so we'd have to add parentheses. But Grime has a really nifty feature where you can change the operator precedence. ^- is like - 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 operator # has too high precedence and would require parentheses around the stuff in front of it, but we can lower its precedence with v to save another byte.

Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Grime, 16 bytes

e`..|!.*.^-d\0.*

Try it online!

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 is neither a string of only two characters ([]) nor contains a zero preceded by a non-digit.

A note about the second half: . matches any character, d matches any digit and - is boolean difference (so we require it to match one character, but disallow that character to be a digit). The only issue is that - has lower precedence than concatenation so we'd have to add parentheses. But Grime has a really nifty feature where you can change the operator precedence. ^- is like - but with higher precedence than any other operator, which is the same as wrapping it and its arguments in parentheses and saves a byte.