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:
- the pattern space format is set to
^current_reputation:needed_reputation#$needed_reputation%$
- 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 - whenif the current_reputation becomesis a "repdigit", the needed_reputation is printed and the program ends