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

Update TIOs to have no-newline end
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
I realized that when used inside a loop, molecular lookahead may be able to do things that are impossible with variable-length lookbehind, because the rollback done by a lookbehind has to be popped out of before going to the next iteration.
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

But because of the difficulty and length of this algorithm, I used molecular lookaheads (of the form (?*...)) to implement it. That is a feature not in ECMAScript or any other mainstream regex engine, but one that I had implemented in my engine. Without any captures inside a molecular lookahead, it's functionally equivalent to an atomic lookahead, but with captures it can be very powerful. The engine will backtrack into the lookahead, and this can be used to conjecture a value which cycles through all possibilities (for later testing) without consuming characters of the input. Using them can make for a much cleaner implementation. (Variable-length lookbehind is for most uses at the very least equal in power to molecular lookahead, but the latter tends to make for more straightforward and elegant implementations. Molecular lookahead may also be able to do things in loops that aren't possible with variable-length lookebehind.)

But because of the difficulty and length of this algorithm, I used molecular lookaheads (of the form (?*...)) to implement it. That is a feature not in ECMAScript or any other mainstream regex engine, but one that I had implemented in my engine. Without any captures inside a molecular lookahead, it's functionally equivalent to an atomic lookahead, but with captures it can be very powerful. The engine will backtrack into the lookahead, and this can be used to conjecture a value which cycles through all possibilities (for later testing) without consuming characters of the input. Using them can make for a much cleaner implementation. (Variable-length lookbehind is at the very least equal in power to molecular lookahead, but the latter tends to make for more straightforward and elegant implementations.)

But because of the difficulty and length of this algorithm, I used molecular lookaheads (of the form (?*...)) to implement it. That is a feature not in ECMAScript or any other mainstream regex engine, but one that I had implemented in my engine. Without any captures inside a molecular lookahead, it's functionally equivalent to an atomic lookahead, but with captures it can be very powerful. The engine will backtrack into the lookahead, and this can be used to conjecture a value which cycles through all possibilities (for later testing) without consuming characters of the input. Using them can make for a much cleaner implementation. (Variable-length lookbehind is for most uses at least equal in power to molecular lookahead, but the latter tends to make for more straightforward and elegant implementations. Molecular lookahead may also be able to do things in loops that aren't possible with variable-length lookebehind.)

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

Return inverse factorial or no-match, in ECMAScript + (?*) + \K (99 bytes99 bytes):

Return inverse factorial or no-match, in ECMAScript + (?*) + \K (99 bytes):

Return inverse factorial or no-match, in ECMAScript + (?*) + \K (99 bytes):

Add 92 byte regex adapted into a 99 byte return inverse factorial regex with molecular lookahead + reset start
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add 92 byte regex adapted into a 103 byte molecular lookahead return inverse factorial regex
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
edited body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add molecular lookahead version of return inverse factorial
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Demonstrate that the 96 byte version returns the inverse factorial minus 1 in a capture group, and edit "accident" -> "coincidence"
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Improve literal accuracy of the comments for the inverse factorial optimized version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
-3 bytes on return inverse factorial version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Optimize the ECMAScript + \K version of the inverse factorial optimized regex
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add comparable ECMAScript + \K version (without the minus 1)
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add a version optimized for returning the inverse factorial as a match
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
-1 byte on "Return inverse factorial or no-match, in ECMAScript + \K"
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
-2 bytes on "Return inverse factorial or no-match, in ECMAScript + \K"
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Optimize the plain ECMAScript version of "Return inverse factorial or no-match" from 112 → 109 bytes
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Oops, had updated the "Return inverse factorial or no-match" TIO but not its plain markdown
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Edit the explanation paragraph to be up-to-date with the 92 byte regex
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Move the -n byte attributions to the top for visibility
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
edited body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Grimy → Grimmy
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Use an atom ⚛ symbol to denote solutions that used non-atomic lookahead
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
-26 bytes thanks to Grimy in collaboration with H.PWiz
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
this should have been done in the previous edit
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Drop 1 byte thanks to a trick found by Grimy
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
1
2

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