Skip to main content
add bijective signed unary version; fix bug in Boost test harness
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Try it online! - Perl
Try it online! - PCRE2
Try it online!Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - .NET

^
(-)?                  # \1 = negative sign if it is present; unset otherwise
(                     # loop the following:
    (x*)\3\3(?=\3$)   # assert tail is divisible by 4; tail = tail / 4
)*                    # iterate as many times as possible (minimum 0)
x                     # tail = tail - 1
(?(1)x)               # if \1 is set, then tail = tail - 1, else do nothing
$                     # assert tail == 0

Regex (ECMAScript or better), 26 bytes

^((.*)\2\2(?=\2$))*(x|oo)$

Try it online! - ECMAScript
Try it online! - Perl
Try it online! - Java
Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - PCRE2
Try it online! - .NET

Takes its input in bijective signed unary. A nonnegative number is a string of x characters, and a nonpositive number is a string of o characters. The the length of the string is the absolute value of the number.

^                     # tail = N = input number
(                     # Loop the following:
    (.*)\2\2(?=\2$)   # Assert tail is divisible by 4; tail = tail / 4;
                      # use "." so that either "x" or "o" can be matched, as
                      # long as all characters are identical.
)*                    # Iterate as many times as possible (minimum 0).
(x|oo)$               # Assert tail == 1 or tail == -2

Try it online! - Perl
Try it online! - PCRE2
Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - .NET

^
(-)?                  # \1 = negative sign if it is present; unset otherwise
(                     # loop the following:
    (x*)\3\3(?=\3$)   # assert tail is divisible by 4; tail = tail / 4
)*                    # iterate as many times as possible (minimum 0)
x                     # tail = tail - 1
(?(1)x)               # if \1 is set, then tail = tail - 1, else do nothing
$                     # assert tail == 0

Try it online! - Perl
Try it online! - PCRE2
Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - .NET

^
(-)?                  # \1 = negative sign if it is present; unset otherwise
(                     # loop the following:
    (x*)\3\3(?=\3$)   # assert tail is divisible by 4; tail = tail / 4
)*                    # iterate as many times as possible (minimum 0)
x                     # tail = tail - 1
(?(1)x)               # if \1 is set, then tail = tail - 1, else do nothing
$                     # assert tail == 0

Regex (ECMAScript or better), 26 bytes

^((.*)\2\2(?=\2$))*(x|oo)$

Try it online! - ECMAScript
Try it online! - Perl
Try it online! - Java
Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - PCRE2
Try it online! - .NET

Takes its input in bijective signed unary. A nonnegative number is a string of x characters, and a nonpositive number is a string of o characters. The the length of the string is the absolute value of the number.

^                     # tail = N = input number
(                     # Loop the following:
    (.*)\2\2(?=\2$)   # Assert tail is divisible by 4; tail = tail / 4;
                      # use "." so that either "x" or "o" can be matched, as
                      # long as all characters are identical.
)*                    # Iterate as many times as possible (minimum 0).
(x|oo)$               # Assert tail == 1 or tail == -2
use powershell TIO for .NET; add Perl, Java, Boost, Python, and Ruby
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Regex (ECMAScript / Java), 38 37 34 33 bytes

Try it online! - ECMAScript
Try it online! - Java

Regex (PCREPerl / PCRE / Boost / Python / Ruby / .NET), 32 bytes

Try it online! - Perl
Try it online! - PCRE2
Try it online!Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - .NET

Regex (ECMAScript), 38 37 34 33 bytes

Try it online!

Regex (PCRE / .NET), 32 bytes

Try it online! - PCRE2
Try it online! - .NET

Regex (ECMAScript / Java), 38 37 34 33 bytes

Try it online! - ECMAScript
Try it online! - Java

Regex (Perl / PCRE / Boost / Python / Ruby / .NET), 32 bytes

Try it online! - Perl
Try it online! - PCRE2
Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - .NET

Update TIOs to have no-newline end
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Silly me - drop the reliance on ECMAScript NPCG behavior
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Show a non-NPCG-specific version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Give the 33 byte version precedence
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
-1 byte in flag-setting ECMAScript version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
-3 bytes in flag-setting ECMAScript version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
-1 byte on the alternate ECMAScript version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Add .NET TIO
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Add PCRE version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Add alternative, 2 byte longer version
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading