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

fix comment on the code relevant to the -2 bytes just applied to the Java version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
x(x*), # 1円 = divisor-1; tail = dividend
( # 2円 = what will be the quotient
 ( # 3円 = the following (after the first iteration has finished),
 # which is always 1
 x # tail -= 1
 (?=
 ( # 4円 = running total
 4円 # recall the previous contents of 4円 (only if it is set)
 1円 # 4円 += divisor-1
 |
 (?!3円) # Match this alternative only if this is the first iteration of
 # the loop, meaning 4円 is unset; 3円 can never not match here if
 # 3円 is set (because 3円==1) unless 1円==0, in which case it
 # doesn't matter if the abovethis alternative is taken instead, of the
 # becauseabove – in that case, the value of 4円 isn't changed anyway.
 1円 # 4円 = divisor-1
 )
 )
 )* # Loop the above as many times as possible (zero or more); if
 # it loops zero times, 4円 will be unset (we'll treat that as 0)
)
4円? # tail -= 4,円 or leave tail unchanged if 4円 is unset
(x*) # 5円 = remainder
x(x*), # 1円 = divisor-1; tail = dividend
( # 2円 = what will be the quotient
 ( # 3円 = the following (after the first iteration has finished),
 # which is always 1
 x # tail -= 1
 (?=
 ( # 4円 = running total
 4円 # recall the previous contents of 4円 (only if it is set)
 1円 # 4円 += divisor-1
 |
 (?!3円) # Match this alternative only if this is the first iteration of
 # the loop, meaning 4円 is unset; 3円 can never not match here if
 # 3円 is set (because 3円==1) unless 1円==0, in which case it
 # doesn't matter if the above alternative is taken instead,
 # because in that case, the value of 4円 isn't changed anyway.
 1円 # 4円 = divisor-1
 )
 )
 )* # Loop the above as many times as possible (zero or more); if
 # it loops zero times, 4円 will be unset (we'll treat that as 0)
)
4円? # tail -= 4,円 or leave tail unchanged if 4円 is unset
(x*) # 5円 = remainder
x(x*), # 1円 = divisor-1; tail = dividend
( # 2円 = what will be the quotient
 ( # 3円 = the following (after the first iteration has finished),
 # which is always 1
 x # tail -= 1
 (?=
 ( # 4円 = running total
 4円 # recall the previous contents of 4円 (only if it is set)
 1円 # 4円 += divisor-1
 |
 (?!3円) # Match this alternative only if this is the first iteration of
 # the loop, meaning 4円 is unset; 3円 can never not match here if
 # 3円 is set (because 3円==1) unless 1円==0, in which case it
 # doesn't matter if this alternative is taken instead of the
 # above – in that case, the value of 4円 isn't changed anyway.
 1円 # 4円 = divisor-1
 )
 )
 )* # Loop the above as many times as possible (zero or more); if
 # it loops zero times, 4円 will be unset (we'll treat that as 0)
)
4円? # tail -= 4,円 or leave tail unchanged if 4円 is unset
(x*) # 5円 = remainder
-2 bytes on Java version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

Regex (Java), (削除) 41 (削除ここまで) 40(削除) 40 (削除ここまで) 38 bytes

x(x*),((x(?=(4円1円|(?!5円3円)1円)()))*)4円?(x*)

Try it online! Try it online!

This is a port of the Perl/PCRE regex to a flavor that has no conditionals. Emulating a conditional costs 5(削除) 5 (削除ここまで) 3 bytes here. The quotient and remainder are returned in the capture groups 2円 and 6円5円, respectively.

x(x*), # 1円 = divisor-1; tail = dividend
( # 2円 = what will be the quotient
 ( # 3円 = the following (after the first iteration has finished),
 x # which is always 1
  x  # tail -= 1
 (?=
 ( # 4円 = running total
 4円 # recall the previous contents of 4円 (only if it is set)
 1円 # 4円 += divisor-1
 |
 (?!5円3円) # matchMatch this alternative only if 4円this is unsetthe first iteration of
 1円 # the loop, meaning 4円 =is divisor-1unset; 3円 can never not match here if
 )
 # 3円 is set (because 3円==1) unless 1円==0, in which case it
  # 5円doesn't =matter setif tothe indicateabove alternative is taken instead,
 # because in that case, the value of 4円 isisn't setchanged anyway.
 1円 # 4円 = divisor-1
 )
 )* )* # Loop the above as many times as possible (zero or more); if
 # it loops zero times, 4円 will be unset (we'll treat that as 0)
)
4円? # tail -= 4,円 or leave tail unchanged if 4円 is unset
(x*) # 6円5円 = remainder

Regex (Java), (削除) 41 (削除ここまで) 40 bytes

x(x*),((x(?=(4円1円|(?!5円)1円)()))*)4円?(x*)

Try it online!

This is a port of the Perl/PCRE regex to a flavor that has no conditionals. Emulating a conditional costs 5 bytes here. The quotient and remainder are returned in the capture groups 2円 and 6円, respectively.

x(x*), # 1円 = divisor-1; tail = dividend
( # 2円 = what will be the quotient
 (
 x # tail -= 1
 (?=
 ( # 4円 = running total
 4円 # recall the previous contents of 4円 (only if it is set)
 1円 # 4円 += divisor-1
 |
 (?!5円) # match this alternative only if 4円 is unset
 1円 # 4円 = divisor-1
 )
 () # 5円 = set to indicate that 4円 is set
 )
 )* # Loop the above as many times as possible (zero or more); if
 # it loops zero times, 4円 will be unset (we'll treat that as 0)
)
4円? # tail -= 4,円 or leave tail unchanged if 4円 is unset
(x*) # 6円 = remainder

Regex (Java), (削除) 41 (削除ここまで) (削除) 40 (削除ここまで) 38 bytes

x(x*),((x(?=(4円1円|(?!3円)1円)))*)4円?(x*)

Try it online!

This is a port of the Perl/PCRE regex to a flavor that has no conditionals. Emulating a conditional costs (削除) 5 (削除ここまで) 3 bytes here. The quotient and remainder are returned in the capture groups 2円 and 5円, respectively.

x(x*), # 1円 = divisor-1; tail = dividend
( # 2円 = what will be the quotient
 ( # 3円 = the following (after the first iteration has finished),
  # which is always 1
  x  # tail -= 1
 (?=
 ( # 4円 = running total
 4円 # recall the previous contents of 4円 (only if it is set)
 1円 # 4円 += divisor-1
 |
 (?!3円) # Match this alternative only if this is the first iteration of
 # the loop, meaning 4円 is unset; 3円 can never not match here if
 # 3円 is set (because 3円==1) unless 1円==0, in which case it
  # doesn't matter if the above alternative is taken instead,
 # because in that case, the value of 4円 isn't changed anyway.
 1円 # 4円 = divisor-1
 )
 ) )* # Loop the above as many times as possible (zero or more); if
 # it loops zero times, 4円 will be unset (we'll treat that as 0)
)
4円? # tail -= 4,円 or leave tail unchanged if 4円 is unset
(x*) # 5円 = remainder
update mrab-regex link; use the elephant emoji I've established to mean "outputs by capture count"
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

Regex (Pythonregex regex / Ruby), 43 bytes

This is a port of the Perl/PCRE regex to flavors that have no support for nested backreferences. Python's built-in re module does not even support forward backreferences, so for Python this requires regex regex.

Regex 🐘(.NET), 14 bytes

Regex (Pythonregex / Ruby), 43 bytes

This is a port of the Perl/PCRE regex to flavors that have no support for nested backreferences. Python's built-in re module does not even support forward backreferences, so for Python this requires regex.

Regex (.NET), 14 bytes

Regex (Pythonregex / Ruby), 43 bytes

This is a port of the Perl/PCRE regex to flavors that have no support for nested backreferences. Python's built-in re module does not even support forward backreferences, so for Python this requires regex.

Regex 🐘(.NET), 14 bytes

add .NET capture-count version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
typo fix
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
added 8 characters in body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
use the format previously used for indicating "import regex"
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
add Ruby TIO; fix range in Python TIO
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
add Python/Ruby version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
-1 bytes - silly me, don't need a possessive quantifier when nothing would cause it to backtrack anyway
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add Java version, 41 bytes; change Perl TIO to go up to 350/350 instead of just 255/255
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add Java version, 41 bytes; change Perl TIO to go up to 350/350 instead of just 255/255
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
linkify the ECMAScript solution, since they're now on separate pages when sorted by Votes
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
fix Perl TIO
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add .NET specific version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Oops, copy pasted this from the other explanation and forgot to edit it.
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading

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