Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

explain why the 28 byte regex is especially interesting
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

This is interesting because if I'd set out to implement that function intentionally, I would have come up with something like ^(?=(x?x+?)1円*$)((?=(x+)(3円+$))4円)?1円$ (38 bytes), which is 10 bytes longer.

It was inspired by the algorithm used by Bubbler's APL answer. The full prime power version of that would be:
^(?!((x+)(?=2円+$)x+)(?!1円*2円+$)1円+$) - ECMAScript, 36 bytes
^(?!((x+)x+)\B(?>1円*?(?<=^2円+))$) - .NET, 33 bytes
^(?!((x+)+)\B(?>1円*?(?<=^2円+))$) - .NET, 32 bytes, 🐌 exponential slowdown

This was inspired by the algorithm used by Bubbler's APL answer. The full prime power version of that would be:
^(?!((x+)(?=2円+$)x+)(?!1円*2円+$)1円+$) - ECMAScript, 36 bytes
^(?!((x+)x+)\B(?>1円*?(?<=^2円+))$) - .NET, 33 bytes
^(?!((x+)+)\B(?>1円*?(?<=^2円+))$) - .NET, 32 bytes, 🐌 exponential slowdown

This is interesting because if I'd set out to implement that function intentionally, I would have come up with something like ^(?=(x?x+?)1円*$)((?=(x+)(3円+$))4円)?1円$ (38 bytes), which is 10 bytes longer.

It was inspired by the algorithm used by Bubbler's APL answer. The full prime power version of that would be:
^(?!((x+)(?=2円+$)x+)(?!1円*2円+$)1円+$) - ECMAScript, 36 bytes
^(?!((x+)x+)\B(?>1円*?(?<=^2円+))$) - .NET, 33 bytes
^(?!((x+)+)\B(?>1円*?(?<=^2円+))$) - .NET, 32 bytes, 🐌 exponential slowdown

added 105 characters in body; deleted 5 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

-2 bytes thanks to H.PWiz; the explanation for why this worked was more complicated
-1 bytes by returning to the original algorithm (with its simple explanation), by a different angleactually constructing values of \$a\$ not divisible by \$b\$ (slower than its 35 byte version32 bytes) instead of asserting \$a\$ is not divisible by \$b\$ (35 bytes); this is slower, but not exponentially so)

-2 bytes thanks to H.PWiz; the explanation for why this worked was more complicated
-1 bytes by returning to the original algorithm (with its simple explanation), by a different angle (slower than its 35 byte version, but not exponentially so)

-2 bytes thanks to H.PWiz; the explanation for why this worked was more complicated
-1 bytes by returning to the original algorithm (with its simple explanation), by actually constructing values of \$a\$ not divisible by \$b\$ (32 bytes) instead of asserting \$a\$ is not divisible by \$b\$ (35 bytes); this is slower, but not exponentially so

added 113 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

-2 bytes thanks to H.PWizPWiz; the explanation for why this worked was more complicated
-1 bytes by returning to the original algorithm (with its simple explanation), by a different angle (slower than its 35 byte version, but not exponentially so)

-2 bytes thanks to H.PWiz
-1 bytes by returning to the original algorithm, by a different angle (slower, but not exponentially so)

-2 bytes thanks to H.PWiz; the explanation for why this worked was more complicated
-1 bytes by returning to the original algorithm (with its simple explanation), by a different angle (slower than its 35 byte version, but not exponentially so)

update user's name
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
fix typo
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Update TIOs to have no-newline end
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Flesh out the regex ports section
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
added 117 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add another answer ported to regex
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
deleted 19 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
added 55 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Re-simplify the explanation
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Adjust the note about the regex inspired by Bubbler's algorithm
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Obsolete the .NET specific exponential-slowdown version with a 32 byte ECMAScript version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Golf the ECMAScript 2018 up-to-squared-prime regex into shorter a universal ECMAScript version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add item of curiosity found while playing around with this
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
fix error in .NET regex's commented explanation and improve explanation of \B
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
added 126 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add 33 (32🐌) byte .NET version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
added 3 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
-2 bytes thanks to H.PWiz
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading

AltStyle によって変換されたページ (->オリジナル) /