Skip to main content
rephrasing and extensive formatting
Source Link
seshoumara
  • 3.7k
  • 1
  • 13
  • 30

GNU sed, 224 bytes

GNU sed, 223 + 1(r flag) = 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t
s/$/:0%/
:;y/:%/%:/
/^(.)\1*%/{s/.*%(.*):/\1/;q}
:f;s/9(@*:)/@\1/;tf
s/8(@*:)/9\1/;s/7(@*:)/8\1/
s/6(@*:)/7\1/;s/5(@*:)/6\1/
s/4(@*:)/5\1/;s/3(@*:)/4\1/
s/2(@*:)/3\1/;s/1(@*:)/2\1/
s/0(@*:)/1\1/;s/(^|%)(@*:)/\11\2/
y/@/0/;t

Run: sed -rf repdigit.sed <<< "112"

sed -rf repdigit.sed <<< "112"

Output:
110

110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation#$needed_reputation%$
  2. in each iteration of the main loop the separators are switched:
    a) #%: will applyapplies the increment to needed_reputation
    b) :#% will applyapplies the increment to current_reputation
  3. whenif the current_reputation becomesis a "repdigit", the needed_reputation is printed and the program ends

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112"

Output:
110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation#$
  2. in each iteration of the main loop the separators are switched:
    a) #: will apply the increment to needed_reputation
    b) :# will apply the increment to current_reputation
  3. when the current_reputation becomes a "repdigit", the needed_reputation is printed and the program ends

GNU sed, 223 + 1(r flag) = 224 bytes

s/$/:0%/
:;y/:%/%:/
/^(.)\1*%/{s/.*%(.*):/\1/;q}
:f;s/9(@*:)/@\1/;tf
s/8(@*:)/9\1/;s/7(@*:)/8\1/
s/6(@*:)/7\1/;s/5(@*:)/6\1/
s/4(@*:)/5\1/;s/3(@*:)/4\1/
s/2(@*:)/3\1/;s/1(@*:)/2\1/
s/0(@*:)/1\1/;s/(^|%)(@*:)/\11\2/
y/@/0/;t

Run:

sed -rf repdigit.sed <<< "112"

Output:

110

This is a pure sed solution, the arithmetic is simulated using regular expressions only. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation%$
  2. in each iteration of the main loop the separators are switched:
    a) %: applies the increment to needed_reputation
    b) :% applies the increment to current_reputation
  3. if the current_reputation is a "repdigit", the needed_reputation is printed and the program ends
added 3 characters in body
Source Link
seshoumara
  • 3.7k
  • 1
  • 13
  • 30

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112"
  

Output: 110
110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation#$
  2. in each iteration of the main loop the separators are switched:
    a) #: will apply the increment to needed_reputation
    b) :# will apply the increment to current_reputation
  3. when the current_reputation becomes a "repdigit", the needed_reputation is printed and the program ends

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112"
 Output: 110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation#$
  2. in each iteration of the main loop the separators are switched:
    a) #: will apply the increment to needed_reputation
    b) :# will apply the increment to current_reputation
  3. when the current_reputation becomes a "repdigit", the needed_reputation is printed and the program ends

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112" 

Output:
110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation#$
  2. in each iteration of the main loop the separators are switched:
    a) #: will apply the increment to needed_reputation
    b) :# will apply the increment to current_reputation
  3. when the current_reputation becomes a "repdigit", the needed_reputation is printed and the program ends
added 66 characters in body
Source Link
seshoumara
  • 3.7k
  • 1
  • 13
  • 30

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112"
Output: 110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra "r"r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_rep:needed_rep#$^current_reputation:needed_reputation#$
  2. in each iteration of the main loop the separators are switched:
    a) "#:"#: will apply the increment to needed_repneeded_reputation
    b) ":#":# will apply the increment to current_repcurrent_reputation
  3. when the current_repcurrent_reputation becomes a repdigit"repdigit", the needed_repneeded_reputation is printed and the program ends

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112"
Output: 110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra "r" flag needed to run the code is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_rep:needed_rep#$
  2. in each iteration of the main loop the separators are switched:
    a) "#:" will apply the increment to needed_rep
    b) ":#" will apply the increment to current_rep
  3. when the current_rep becomes a repdigit the needed_rep is printed and the program ends

GNU sed, 224 bytes

s/$/:0#/
:
y/:#/#:/
/^(.)\1*#/{s/.*#(.*):/\1/;q}
:f
s/9(@*:)/@\1/
tf
s/8(@*:)/9\1/
s/7(@*:)/8\1/
s/6(@*:)/7\1/
s/5(@*:)/6\1/
s/4(@*:)/5\1/
s/3(@*:)/4\1/
s/2(@*:)/3\1/
s/1(@*:)/2\1/
s/0(@*:)/1\1/
s/(^|#)(@*:)/\11\2/
y/@/0/
t

Run: sed -rf repdigit.sed <<< "112"
Output: 110

This is a pure sed solution, the arithmetic is simulated using regular expressions only and as such no shell calls were made from sed. The extra r flag needed to run the code properly is counted in the bytes total. The algorithm works as follows:

  1. the pattern space format is set to ^current_reputation:needed_reputation#$
  2. in each iteration of the main loop the separators are switched:
    a) #: will apply the increment to needed_reputation
    b) :# will apply the increment to current_reputation
  3. when the current_reputation becomes a "repdigit", the needed_reputation is printed and the program ends
Source Link
seshoumara
  • 3.7k
  • 1
  • 13
  • 30
Loading