[Question]
  [
# Intro
Find the result of number cannibalism.
Why was 6 scared of 7? Becase 7 `8` 9.
Your program will have to find the result of applying the `8` operation(defined below) on a number, repeatedly.
[Related](https://codegolf.stackexchange.com/questions/66603/why-was-6-afraid-of-7), [Sandbox](https://codegolf.meta.stackexchange.com/a/19390/80214)
# Challenge
Your input will be a single positive integer, n.
You need to find each `8` in the integer, and substitute it for `+` or `-` based on the following conditions.
* remove all `8`s at the beginning or end of the string.
* If there are multiple `8`s, then collapse them into a single `8`.
* \$a\$ and \$b\$ are the chunks to the left and right of the `8` respectively. Since `8` is an operator, the numbers are delimited by `8`.
* If \$ a ‚â• b,\$ `8` becomes `+`.
* else, it becomes `-`.
Then evaluate the expression from left to right, and take the absolute value.
If the result has any `8`s in it, the repeat the above steps again till there are none.
For example, `12384568789` becomes:
```
123 456 7 9
123 < 456: 123 - 456 7 9
456 ‚â• 7  : 123 - 456 + 7 9
7 < 9    : 123 - 456 + 7 - 9 = -335
= abs(-335)
= 335
```
Hence 335 is the final answer.
# Example Input and Output
```
789 ‚Üí¬†2
180 ‚Üí 1
42312348 ‚Üí 4231234
2389687 ‚Üí 66
12384568789 ‚Üí 335
13749547874394873104972349 ‚Üí¬†7309154
808 ‚Üí 0
7800482 ‚Üí 13
14458883442 ‚Üí 1997
88888 ‚Üí indeterminate
388182 ‚Üí 2
08182 ‚Üí 3
```
Here are the testcases as an array:
`[789,180,42312348,2389687,12384568789,13749547874394873104972349,808,7800482,14458883442,88888]`
## Scoring Criteria
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in each language wins.
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~18~~ 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Œî8¬°√æD√º@1≈°¬∑<*O√Ñ
```
[Try it online](https://tio.run/##AToAxf9vc2FiaWX//86UOMKhw75Ew7xAMcWhwrc8Kk/DhP//ODEzNzQ5NTQ3ODc0Mzk0ODczMTA0OTcyMzQ5) or [verify all test cases](https://tio.run/##FYoxCsJAFAWvElLKL3b3v/W/BSEW9h5ALBQsrCwEIYWd5ADiBXIKG7HIYushvMiaTDUDczrv9sdDubRNXf26e1U3bfk@OPT5vcqvpf/0w3MxW@dbuUrZGJN4OkFQHxSUoExzmoxFxNGmQQ0pwmjQBJp6h2TjnoSOYnQODOKBSFKBIJwQJT3D9g8).
**Explanation:**
```
Œî               # Loop until it no longer changes:
 8¬°             #  Split the integer on 8s
                #  (which will use the implicit input-integer in the first iteration)
   √æ            #  Remove all empty strings by only leaving digits
    D           #  Duplicate this list
     √º          #  For each overlapping pair [a,b]:
      @         #   Check if a>=b (1 if truthy; 0 if falsey)
       1≈°       #  Prepend a 1 to this list
         ¬∑      #  Double each value
          <     #  Decrease each by 1 (0 has become -1; 1 is still 1)
           *    #  Multiply the values at the same positions in the two lists
            O   #  Sum the list
             √Ñ  #  And take the absolute value of this sum
                # (after which the result is output implicitly)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~20~~ 18 bytes
```
I≈ª·π†o-√ó
·π£8L∆á·∏å√áSA¬µ√êL
```
[Try it online!](https://tio.run/##FcohDgIxFEVRz1o@Sdv/yn@VSJJxKBaAIZOgsZgaBA5LgsVOwgRHA/sYNlKKuzc5u23fH2pdvZ/TeN3Py2U2jTd2nzw9TiWvl6@hnLta8vd439RqTOLpBEF9UFCCMi1o0o6Irf5ADSnCaNAEmnqHZI0noaMYnQODeCCSVCD8AA "Jelly ‚Äì Try It Online")
Went through 5 or 6 other approaches before eval turned out to be the only one I could get to work... and then I tried a different spin on my second approach and it's 2 bytes shorter.
Old version: `·π£8L∆á·∏å<∆ù·ªã‚Åæ_+≈º@∆≤FVA¬µ√êL`
```
I≈ª·π†o-√ó         Monadic helper link:
  ·π†            signs of
I              deltas
 ≈ª             with prepended 0,
   o-          replace all 0s with -1s,
     √ó         pairwise multiply with argument.
·π£8L∆á·∏å√áSA¬µ√êL    Main link:
·π£8             split (implicitly converted digit list) on 8s,
  L∆á           remove empty slices,
    ·∏å          convert digit lists from decimal,
     √á         apply helper link,
      S        sum,
       A       abs.
        ¬µ√êL    Loop that whole thing until it doesn't change.
```
[Answer]
# JavaScript (ES6), 76 bytes
```
f=n=>n.replace(p=/[^8]+/g,x=>t-=p<(p=+x)?x:-x,t=0)&&n-(t=t<0?-t:t)?f(t+''):t
```
[Try it online!](https://tio.run/##fdHBioMwEAbge59CPLQGm5pkRjORpj7IsgviatkiKm0ovr0rdPditDmGfMz/T27ls3xU95/B8a7/rqepsZ29dKd7PbRlVUeDTT6@6DNOrsfRXhy3w3m@i0dWjDkfj84Ktt93PHLWnUXBXe5Y0UQuPhxY7qaq7x59W5/a/ho1UajJhMH6YSxIkkDtFkKSeC/kUqACqQAp3BJ/D5ZOAZmMdLg5Kcu8cLPBdEZ@rRcBSD0DGk2KmjSCQdIgBRo95zHhy2gQRqZePBL0fhFi5y1bCCS1XUiCFw4xJSJAVOuFpDF6iYBIro/5/9TpFw "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
f = n =>               // f is a recursive function taking n as a string
  n.replace(           // we look for ...
    p = /[^8]+/g,      // ... all groups of consecutive non-eight digits
    x =>               // for each group x:
      t -=             //   update t:
        p < (p = +x) ? //     if the previous value is less than x:
          x            //       subtract x from t
        :              //     else:
          -x,          //       add x to t
    t = 0              //   start with t = 0
  ) &&                 // end of replace()
  n - (                // if n is not equal to t,
    t = t < 0 ? -t : t // where t is first updated to its absolute value:
  ) ?                  //
    f(t + '')          //   do a recursive call with t (coerced back to a string)
  :                    // else:
    t                  //   success: return t
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~27~~ ~~26~~ 25 bytes
*Edit: -1 byte by using `S` combinator to recycle function argument, and moving helper function in-line, and then -1 more byte by a bit of rearrangement to be able to use `o` combinator instead of `()`*
```
œâ(aŒ£Sz*o:1·∫ä»Ø`^_1¬¨<mdfIx8d
```
[Try it online!](https://tio.run/##yygtzv7//3ynRuK5xcFVWvlWhg93dZ1YnxAXb3hojU1uSppnhUXK////DY2MLUxMzSzMLSwB "Husk ‚Äì Try It Online")
A *slightly* different approach to [Unrelated String's Husk answer](https://codegolf.stackexchange.com/a/213721/95126), ~~also 27 bytes~~.
I'd held-off posting this for a bit, to give any new Husker a clean slate from which to try out this challenge... but now the Husketition is open...
**How?**\*
```
mdfIx8d                 # helper function: splits input on 8s
      d                 # get digits of input
    x8                  # split on 8  
  f                     # remove elements that are falsy for
   I                    # the identity function (so, remove empty elements)
m                       # map over each element of the list 
 d                      # combining digits as decimal number
 
œâŒªaŒ£z*‚ÇÅ¬πm`^_1Œò·∫äo¬¨<‚ÇÅ     # main program
œâ                       # repeatedly apply function until results are constant
 Œª                      # lambda function taking one argument:
  a                     # get the absolute value of
   Œ£                    # the sum of all elements of
    z*                  # element-wise multiplication of
      ‚ÇÅ¬π                # (1) helper function applied to input
                        #     (so: the input split on 8s)
        m               # (2) map this function to all elements of
                  ‚ÇÅ     #     helper function applied to input
             Œò          #     (with 0 prepended at the start)                 
         `^_1           #     minus one to the power of
              ·∫ä         #     the results for each pair of elements
               o        #     combine 2 functions
                ¬¨       #     NOT
                 <      #     second is greater than first    
```
[Answer]
# [R](https://www.r-project.org/), ~~89~~ 122 bytes
*Edit: +33 bytes to convert to recursive function when I realized that it should repeat the `8` operation on its own output until there are no more `8`s. Doh!*
```
f=function(s)`if`(grepl(8,a<-abs(sum(c(1,-sign(diff(n<-sapply((n=el(strsplit(s,8)))[n>-1],as.double))))*n))),f(c(a,'')),a)
```
[Try it online!](https://tio.run/##fY9BbsIwEEX3OUUEC8Yoqex4gscS6UWqShhwkKVgIjss2gP0AD1iL0KN1AZCpXphWfO///sTLjvjvduazr3b5tI27dnvBnfyENnGtRs4BNt3QIVZl2YbIZ6PsANRlNEdPOxd24Jfl9H0ffcG4BvbQRxC7Ds3QCyIMfbin0vxWpj4tD@dt51NI7b06SralGSKxSI9DbvvATNRScJ6RYr0jOXzXMo6mxh@ha@Pz7yaSoL4KImphJVMyUij/jOYuhJbJ/RoWq2yf8tdPX8KCqlQ16hIodRISgqOWiXW7Y@SXIv6AU781o4/7sw5UnVbTj4gEWsikoh3Hq1VNs@niOsZHc7v7WDD0Xkz2LzJbQinMA2WROKOW2WXbw "R ‚Äì Try It Online")
Accepts argument `n` as a string. Errors for `n`s containing no non-8 digits/characters.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~158~~ ~~148~~ ~~145~~ 138 bytes
```
x=input()
while'8'in x:
 y=[int(f)for f in x.split('8')if f];x=str(sum([-1,1][y[i-1]<y[i]]*y[i]for i in range(len(y))))
print(abs(int(x)))
```
[Try it online!](https://tio.run/##FYzBDsIgGIPvewpuA@OMCIah7kkIh5kM9yeTEWARnh6hhzb50tbluO6WlZImsO6ImHS/FbalH3uwKD06lCcFNmJDzO6RQY1egtsg4tohYJDRzzSF6HE4vlgN9Ey1ygoGql81tD41b2NoYz/bz4K3xeJMqjrn2/v8DrhlqqgUygSXdy5GwZnko2D0yqW4MS7/ "Python 3 ‚Äì Try It Online")
*-10 bytes thanks to @pavi2410 and to me not being an idiot and accidentally leaving an extra space from the golfing suggestion*
*and another -3 thanks to @pavi2410*
*and another -7 thanks to @pavi2410*
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~149~~ \$\cdots\$ ~~139~~ 137 bytes
Saved 2 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!!!  
Saved 8 bytes thanks to [AZTECCO](https://codegolf.stackexchange.com/users/84844/aztecco)!!!
```
R;t=10;m;s;p;c;f(n){R=n;for(s=p=0;n;){for(m=1,c=0;n&&n%t-8;n/=t,m*=t)c+=n%t*m;s+=c>p?p:-p;for(p=c;n%t==8;)n/=t;}p=abs(s+c);R=p-R?f(p):p;}
```
[Try it online!](https://tio.run/##bVJNb@MgEL3nV4wipTI2Vuw4TUhnaQ@rlfaca5ODS3AbKSbIsJV3I//27GC7UbtaJASP9zEwQqWvSl2vW/Qyz7BGhxYVVpFhl600WJ2byEkrMzTILgHVMucq4Ls7M/OpQDOXntex9Ewlko5iCkmkerRP9iG1fYKVComRUiALcuysLF9c5BLFcCttun2qIsseLHbXo/FQl0cTscllAjTmMfws3zX4M@hWnX4dNLhzTVg7D6UD/6Z/Q9loOJXNq24IlwZCSjzv/WEbtO55DxIua7HhkIuMw3JR5ItiKTgsCrFZiTUHkRFaiyxbigWhMDgUQuQBrkXe4S1St1Yrrw9DKtH5LZHDasWBKuRFvxCZjU71VjYxNINpumt/LHbt5jvN@ymHz7iYjg7qH0Sh4NEcdEu2DMftN3DHP/pcRf3r2HxE8QARkqTXMRj6@HFxMBQyNKTn9/iV1kTfHvevwjakqaLp7ADpI9CdDftqb7R/L08UEb7Qf30ztzNkHIS0Pn9YqOx@tHST7voX "C (gcc) ‚Äì Try It Online")
### Explanation (before some golfs)
```
t=10;                                 // golf by storing 10 in t
g(n){                                 // helper function takes int n  
     for(     ;n;){                   // loops until n is zero  
         s=p=0                        // init sum s and previous p to 0  
       for(                           // inner loop calculates next rh value  
           m=1,                       // init multiplier m to 1  
               c=0;                   // and current c to 0   
                   n&&                // loop until n is 0   
                      n%t-8;          // or most rh digit is 8     
                            n/=t,     // knock most rh digit off n      
                               m*=t)  // and bump m by 10 each loop  
         c+=n%t*m;                    // add next digit to current 
                                      // building up number after  
                                      // most right-hand 8  
      s+=c>p?p:-p;                    // after that's done update sum s  
      for(                            // loop to strip off all rh 8's  
          p=c;                        // also make previous = current  
              n%t==8;)                // loop until most rh digit isn't an 8  
                      n/=t;           // knock most rh 8 off n   
        }                             //   
 p=abs(s+c);                          // return abs value of sum with   
                                      // positive most lh value  
}                                     //  
f(n){                                 // recursive main function  
     x=g(n);                          // calc first iteration
            x=x-g(x)?                 // is it different to next iteration?  
                     f(x):            // if so iterate  
                          x;          // else return value   
}                                     //  
```
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 59 bytes
```
y/8/ /;s/\d+/$&<$'?"$&-":"$&+"/ge;$_=abs eval$_.0;/8/&&redo
```
[Try it online!](https://tio.run/##LY1taoRADIb/zykGGSx02Z2PZEymtvQihcXiUASrorKwF@gBesQepNOpmh8h70OeZIpz79Oi5eVR6zrdNWup60W/tSetymf18Fqo8lw85X4q9Ees1fWleV9kvDW9ul5MnYWynGM7pkQc5M/Xt3TCstkmK9CBdYC8xSMIBxwqpo1VlciM0Wdw@ABeWCAMHokJISATWIOBsryvEJhgPQo2@2UjiI1BdvtbEBbRMzMgHigEEvxfW@yGNq5x/uyGZo0CmO2hut9xWrtxWNJ56v8A "Perl 5 ‚Äì Try It Online")
[Answer]
# [J](http://jsoftware.com/), 53 bytes
```
|@('8'+/@(*_1x^0,2</\])@(,(*@#;._1#".;._1)~[=,)":)^:_
```
[Try it online!](https://tio.run/##VY8xT8NADIV3foWVDsmVND2ffbF9UCkSEhMTK9AMVSvEwtoB8ddDkI@BwbLe96xn@2NphvYChwIt9BChrLUb4OH56XH5mrpW29v91G1nvB5jn@73r29h6vpuO23uhhk3zfDbwvfLoQ9NCccyL@HmfHr/hAS7AhcQNdfoGjW65kSYiJ1WoW6No9NEaqOKQ6JcE1bMeeVq4JZQNMw1CknYMosKk7EKYWSTNdyuPh19TmPdhvR3aYysqUIzqXnMWVWJOcG/z0gVNS0/ "J ‚Äì Try It Online")
### How it works
* `f^:_`: until the result does not change, do f.
* `'8'‚Ä¶(,g[=,)":`: convert the input to a string, prepend `,` the character `8`, and execute `g` with this as the left argument, and a bit mask of `8` characters as the right argument.
* `(‚Ä¶".;._1)~`: split the string into groups `u;._1`, which start with 1 in the bit mask and convert them back to numbers `".` (excluding the `8`).
* `*@#;._1#`: because we could have empty groups (`888`), take `#` only those, whose length's `#` signum `*` is 1. (There might be a nicer approach.)
* `2</\]`: compare `<` each group with its following, resulting a bit-mask.
* `*_1x^0,`: prepend a 0 to the bit mask, and calculate `x*(-1)^y` for each group `x` with `y` being the result of the comparing. So we get `3 1 2 -> 3 1 _2`.
* `|@‚Ä¶+/`: sum `+/` the result and take the absolute value `|`.
[Answer]
# [Scala](http://www.scala-lang.org/), ~~94~~ 90 bytes
```
i=>"[^8]+".r.findAllIn(""+i).map(_.toInt).scanRight(0){(a,b)=>if(a<b.abs)a else-a}.sum.abs
```
[Try it online!](https://tio.run/##lczBT4MwFAbwO3/Fk1MbXAujuLIICccl8@LV6PJgZXbpCqHVaJb97YhZMrn6nV6@9@XnGjQ4dvVRNR6eUFtQX17ZvYOq7@EcfKKBdg3bzh6gKKGy31AEnO9YRMKQMtcb7Ukoo@lutfFqmOq7grIT9mTHfLexflo1aJ/14d2TmJ4J3te0KHVL8LFmWDu6QFDGKcALcx@n32rURRm@vMnXKGTDBNt9ZczGTnak/2df6cWM7gdtvbGkJckylSJ7kCuZbymFazhP0yz4G8lY3n63cB7PJokQmZQyFWI5d5I8XwWX8Qc "Scala ‚Äì Try It Online")
-4 bytes by not using Java's cursed `split` method.
```
i=>                           //The input
  "[^8]+".r                   //Regex for operands
  .findAllIn(""+i)            //Get all separate numbers in the input
  .map(_.toInt)               //Turn them into integers
  .scanRight(0){(a,b)=>       //Starting at the right,
    if(a<b.abs)a else-a}      //Replace a with -a if a >= b.abs (this is different from the challenge, but it works because we call abs again later)
  .sum                        //Sum them up
  .abs                        //Take the absolute value
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 27 bytes
```
œâ(aŒ£Sz*(·∫ä»Ø`^_1¬±>·π†:‚Üê)mdfIx8d
```
[Try it online!](https://tio.run/##yygtzv5/aFvuo6bG/@c7NRLPLQ6u0tJ4uKvrxPqEuHjDQxvtHu5cYPWobYJmbkqaZ4VFyv///6PNLSx1DC0MdEyMjA2NjE0sdIyMLSzNLMx1gDwLE1MgC6TA2NzE0tTE3MLcxNjSxMLc2NDAxNIcqNxSx8LAQsfcwsDAxMJIx9DExNTCwsLYxMQoFgA "Husk ‚Äì Try It Online")
This isn't quite my first Husk answer, but it's a pretty clumsy direct translation of one of my attempted Jelly answers, so it could at least serve as a serviceable starting point for someone to swoop in and earn the bounty.
```
œâ(                             Iterate until periodic:
  a                            absolute value of
   Œ£                           sum of
     z*                        zipwith multiplication on:
                          d    decimal digits
                        x8     split on 8s
                      fI       with empty slices removed
                    md         and converted back from decimal,
    S                          and the result of that
       (        ·π†:‚Üê)           with its first element duplicated
        ·∫ä                      and with neighboring pairs mapped to
          `^_1                 -1 to the power of
         »Ø    ¬±>               if the first is less than the second.
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 177 bytes
```
A=($(sed s/8/\ /g<<<$1));B=;while [ ${#A[@]} -ge 2 ];do [ ${A[0]} -ge ${A[1]} ]&&C=+||C=-;B=$B${A[0]}$C;A=(${A[@]:1});done;R=$(bc<<<$B$A|tr -d -);grep -cq 8 <<<$R&&f $R||echo $R
```
It has to be stored as function `f` or in file `f` in the current working directory.
[Try it online!](https://tio.run/##LU/LbsIwEDw3XzGiVhSriojjpd7UpGrgxBVxAw4lD0CqkhaoeiB8e2oj9jS7O5rH7vN8GJrftrwcuxZNJHEdijwS0bmucB7zeIPxfjqdCiWlneX273D8qrGGuD4X64/tDfG@Roqtrbr7tVgnj6PHyuFtGM7zl76f57ETELMHR8yt97l6lTd1k06gre0yF9Gu9H4zUfSXE@IKsbT7U/2NuPwBw/@WYdhALPu@Lg@dA8MtCFZ5BMMZFCegVKtUEyPVnL2ygduYJg55gjaUTciwIZ0RG60SyoyjZ@CEnUaSEKdQRBNm1kQp2A9k0HQnLHBsXbeVL29RdcHTPcRILBC/Q0Qu2EKObODrDP8 "Bash ‚Äì Try It Online")
[Answer]
# PHP, 290 bytes
(Guess you shouldn't golf in php. :) )
```
<?php $n=$_SERVER["argv"][1];while(false!==strpos($n,'8')){$n=abs(array_reduce(str_split(preg_replace('|8+|','8',trim($n,'8')).'8'),function($c,$i){if($i!=8){$c[1]*=10;$c[1]+=$i;}else{$c[2]+=$c[1]*((!isset($c[0])||$c[0]>=$c[1])?1:-1);$c[0]=$c[1];$c[1]=0;}return$c;},[null,0,0])[2]);}echo$n;
```
[Try it online](http://sandbox.onlinephpfunctions.com/code/d624e56da25e682d5cb6e4e2516977583918ba9f)
## Ungolfed:
```
<?php
$n = $_SERVER["argv"][1];
$f=function($c, $i){
    if($i!=8) {
        $c[1]*=10;
        $c[1]+=$i;
    } else {
        $c[2] += $c[1] * ( (!isset($c[0]) || $c[0]>=$c[1])?1:-1);
        $c[0]=$c[1];
        $c[1]=0;
    }
    return $c;
};
while(false!==strpos($n,'8')) {
    $n = trim($n, '8');
    $n = preg_replace('|8+|', '8', $n);
    $a = str_split($n.'8');
    $n = abs(array_reduce($a, $f, [null, 0, 0])[2]);
}
echo $n;
```
## Explanation:
I use array\_reduce to walk over every digit, and use an array as carry to have 3 datapoints carried on: the variables $a, $b and $sum, though they are unnamed as the elements of $c.
If the current digit is a non-8, I "add" it to my "$b", otherwise I first compare $b to $a, add/subtract $b from $sum, and move the content of $b to $a.
[Answer]
# [Red](http://www.red-lang.org), 142 bytes
```
func[n][while[find to""n"8"][b: to[]load form split to""n"8"forall b[if b/2[b/1:
reduce[b/1 pick[- +]b/1 < b/2]]]n: absolute do form b]to 1 n]
```
[Try it online!](https://tio.run/##PY/dbsMgDIXv8xQWt1PU/NDVzaY9xLQ75AsIpEWlEBGiPX5GSDXf@HzW8ZEdjd6@jRZUTQNs0@pH4Un83q0zYrJeQwqMeYaMhBoyCHJBaphCfMIyO5v@DXkknQMl7ATq1Al1aocqGr2OZtcw2/EhanijHT53CxH5AaRagluTAR2OWEUpQAuetiqzkeMdPIgKcl3wWnqLTem869uu51ig6/H6jpfDkIGfM70WsMFXQNNw7A4P52dE7Dk/@ANwr6Ly5yaZ@LRe5stq@In2djNxAenBxBhi2egR2xxGAuZofRLlfA@s/mIwZUG0/QE "Red ‚Äì Try It Online")
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 32 bytes
```
.,{8`%(~:x\{~.x\:x<2*(*-}/abs`}*
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/X0@n2iJBVaPOqiKmuk6vIsaqwsZIS0NLt1Y/Mak4oVbr/39DY3MTS1MTcwtzE2NLEwtzY0MDE0tzI2MTSwA "GolfScript ‚Äì Try It Online")
Every time the algorithm is executed, the number either stays the same or it gets at least 1 digit shorter. This means we can execute the algorithm once for every byte instead of testing if it has an 8.
```
.,                                 # Get the number of bytes in the input
  {                           }*   # Execute this block that many times
   8`%                             # Split the string around the 8s and remove the empty strings
                                   # This simultaneously executes the first 3 steps
      (~                           # Get the first number
        :x                         # Store it in the variable x
          \{~           }/         # For each number left in the array
             .x                    # Copy it and push x
               \:x                 # Store the current number in x
                  <                # Compare the two numbers
                   2*(             # 1 if previous<current and -1 if previous>=curret
                      *-           # Multiply and subtract
                          abs`     # Parse the absolute value to a string
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 37 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
@=q8 f;=√§√àn ¬®Y?Y:-Y}Ug)x a s ,U√∏8}f U
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=QD1xOCBmOz3kyG4gqFk/WTotWX1VZyl4IGEgcyAsVfg4fWYgVQ&input=LW0KWyI3ODkiLCIxODAiLCI0MjMxMjM0OCIsIjIzODk2ODciLCIxMjM4NDU2ODc4OSIsIjEzNzQ5NTQ3ODc0Mzk0ODczMTA0OTcyMzQ5IiwiODA4IiwiNzgwMDQ4MiIsIjE0NDU4ODgzNDQyIiwiODg4ODgiLCIzODgxODIiXQoiNzg5IFx1MjE5MiAyCjE4MCBcdTIxOTIgMQo0MjMxMjM0OCBcdTIxOTIgNDIzMTIzNAoyMzg5Njg3IFx1MjE5MiA2NgoxMjM4NDU2ODc4OSBcdTIxOTIgMzM1CjEzNzQ5NTQ3ODc0Mzk0ODczMTA0OTcyMzQ5IFx1MjE5MiA3MzA5MTU0CjgwOCBcdTIxOTIgMAo3ODAwNDgyIFx1MjE5MiAxMwoxNDQ1ODg4MzQ0MiBcdTIxOTIgMTk5Nwo4ODg4OCBcdTIxOTIgaW5kZXRlcm1pbmF0ZQozODgxODIgXHUyMTkyIDIi)
* takes input as a string, it can be easily modified to take input as a number but it won't work with big numbers
'''
```
@=q8 f;=√§√àn ¬®Y?Y:-Y}Ug)x a s ,U√∏8}f U
@....}f    - return first number which return false when passed through @...
=q8 f;     - input splitted on 8 and empties removed
=√§√à...}Ug) - pass each consecutive values through √à , but prepend first value before so that they are >=
n ¬®Y?Y:-Y  - 1st to number compared to 2nd: return 2nd (negated eventually)
x a s      - reduce->abs->to string
The above is assigned to U while the funxtion returns..
U√∏8        - contains 8? => repeat
Finally we return U
```
'''
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), ~~60~~ ~~43~~ 38 bytes
-22 bytes thanks to Traws
```
{a|-a:+/{x*1-2*>':x}.:'(~^.)#"8"\$:x}/
```
[Try it online!](https://tio.run/##FYo7DoMwEAWvsoJIBiKD90N4uMhJokg0NBS0SJBc3dlM9eZptrhvpaz5XK645PtwHh1H6Z4hH58@h@b77tu6QvW6@TGUNdCEmRiJTJRFDSSK@YGJ3GCjLw@Q4GFKBiE2GwGomRD@kAIMKT8 "K (oK) ‚Äì Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 68 bytes
```
{`8+
-
^-|-$
\d+
$*
(?=-(1*))(?<=\1)-
+
O`\D1*
\+
1>`-
(1+)-\1
1
```
[Try it online!](https://tio.run/##FYgxCgIxFAX7d44Vkg0f8pOseQuu2wiWXiBIBC22sRA7vXuMU83M6/Henre2M@faPpUOgqt8ZQDK3WEYYdZFjI7WmvWwFLUCh0stJx1RHKDHKoBRZ6Voz9YyZyg9QuS8Z4Z2SVO3/umJTO8TAzSliWRMKYB/EEll@AE "Retina 0.8.2 ‚Äì Try It Online") Link includes smaller test cases (Retina has to do subtraction in unary, which is too slow for the larger cases). Explanation:
```
{`
```
Repeat until there are no `8`s left.
```
8+
-
```
Convert each runs of `8`s to a `-`.
```
^-|-$
```
Delete leading and trailing `-`s.
```
\d+
$*
```
Convert the remaining numbers to unary.
```
(?=-(1*))(?<=\1)-
+
```
Replace each `-` with a `+` unless the following number is greater.
```
O`\D1*
```
Sort the numbers to be added to the beginning and the numbers to be subtracted to the end.
```
\+
```
Add all the numbers to be added together.
```
1>`-
```
Add all the numbers to be subtracted together.
```
(1+)-\1
   
```
Take the absolute value of the difference.
```
1
```
Convert it to decimal.
]