[Question]
  [
Say I have an expression:
```
9 * 8 + 1 - 4
```
This expression can be interpreted in six different ways, depending on operator precedence:
```
(((9 * 8) + 1) - 4) = 69 (* + -)
((9 * 8) + (1 - 4)) = 69 (* - +)
((9 * (8 + 1)) - 4) = 77 (+ * -)
(9 * ((8 + 1) - 4)) = 45 (+ - *)
((9 * 8) + (1 - 4)) = 69 (- * +)
(9 * (8 + (1 - 4))) = 45 (- + *)
```
Say I'm a developer, and I don't feel like memorizing precedence tables, etc., so I'm just going to guess.
In this case, the largest margin of error would be 45-77, which is a difference of 32. This means that my guess will only be off by a maximum of 32.
## The challenge
Given an expression consisting of numbers and `+`, `-`, `*`, `/` (integer division) and `%`, output the absolute difference of the largest and smallest possible value for that expression, based on the precedence of operators.
## Specifications
* The input expression will not contain parenthesis and every operator is left-associative.
* The input expression will only contain nonnegative integers. However, subexpressions may evaluate to negatives (e.g. `1 - 4`).
* You can take the expression in any reasonable format. For example:
	+ `"9 * 8 + 1 - 4"`
	+ `"9*8+1-4"`
	+ `[9, "*", 8, "+", 1, "-", 4]`
	+ `[9, 8, 1, 4], ["*", "+", "-"]`
* The input will contain at least 1 and at most 10 operators.
* Any expression that contains a division or modulo by 0 should be ignored.
* You can assume that modulo will not be given negative operands.
## Test Cases
```
9 * 8 + 1 - 4             32
1 + 3 * 4                  3
1 + 1                      0
8 - 6 + 1 * 0              8
60 / 8 % 8 * 6 % 4 * 5    63
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~171~~ 156 bytes
```
lambda a:max(e(a))-min(e(a))
u=')%s('
def e(a,t=u):
 try:b=[eval(a)]
 except:b=[]
 return sum([e('(%s)'%a.replace(o,t%o),u%t)for o in"+-*/%"if' '+o in a],b)
```
[Try it online!](https://tio.run/##ZYzNasMwEITvfoohIKT1TxOnaUgMfpI0BzmRqMGWjCyV5OmdTQsl0MOyO9/M7HSPX95tF9t@LoMeu6uGbkZ9U0Zpomrs3e@VpVaSmJXMrsaCURnbRE2GGO5N157Mtx44d85gbhczxSdjEUxMwWFOozoZJZWYSQr9Fsw06ItRvozCU5lEJOsDPHq3Kqp8LVa9lZDFE0Cfy46WKfQuwip5RI4DCtSosJOU/Rk1w3c2/8H6FRy4tv@p59i8GvsN1vxY8OScENjx/pC0PAA "Python 2 – Try It Online")
### How it works
We surround each operator with a different number of outward-facing pairs of parentheses to simulate different precedences (in all possible ways), and wrap enough inward-facing pairs of parentheses around the entire string, to get an expression we can `eval`. For example, with
`+` ↦ `)+(`  
`*` ↦ `))*((`  
`-` ↦ `)))-(((` 
we get
`9 * 8 + 1 - 4` ↦ `(((9 ))*(( 8 )+( 1 )))-((( 4)))` = `77`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 126 bytes
"Operator Precedence? Parentheses? Pah, who needs that?" - challenges of using Jelly for an operator precedence challenge.
```
⁾[]i$€Ḥæ%3+\¬œp¹Ḋ€
ÇµḟØDO%9µÐṀṪɓœṣ⁹,ṚÑj@¥/
ÇµVṾµ1ĿFḟØDḟ”-Lµ?ÐL
5Ḷx@€“]“[”ż⁸j/€,@y³Fɓ³i@€Ṁ’x@“[“]”jÇ
“+_×:%”Œ!Ç€µṾL_L’ỊµÐfV€ṢIS
```
[Try it online!](https://tio.run/##y0rNyan8//9R477o2EyVR01rHu5YcniZqrF2zKE1RycXHNr5cEcXUJTrcPuhrQ93zD88w8Vf1fLQ1sMTHu5seLhz1cnJRyc/3Ln4UeNOnYc7Zx2emOVwaKk@WHHYw537Dm01PLLfDaINSD5qmKvrc2ir/eEJPlymD3dsq3AAmvyoYU4sEEcDJY/uedS4I0sfKKjjUHlos9vJyYc2Z4LUAO161DATqBysDqR@btbhdi4gUzv@8HQrVZDeSYqH24FKga7cuc8n3geo/uHuLpBD08LAJizyDP7//7@SRbyZtuHh6QZKAA "Jelly – Try It Online")
Input is taken as a string, e.g. "1+2\_3×4:5%6". Note multiplication uses "×" instead of "\*", division uses ":" instead of "/", and subtraction uses "\_" instead of "-".
**How it Works**
The program is divided into three parts: generating all expressions of different operator precedence, evaluating them, and returning the difference between the maximum and minimum.
All expressions are generated with the code:
```
5Ḷx@€“]“[”ż⁸j/€,@y³Fɓ³i@€Ṁ’x@“[“]”jÇ (4) helper link: returns all outputs given a permutation. Input e.g. "_+:×%"
5Ḷx@€“]“[”           - repeat outer brackets to get ["",""],["]","["],["]]","[["],["]]]","[[["],["]]]]","[[[["]
          ż⁸j/€      - insert the operations in to get "_","]+[","]]:[[","]]]×[[[","]]]]%[[[["
               ,@    - turn this into a mapping equivalent to "_"↦"_","+"↦"]+[",":"↦"]]:[[","×"↦"]]]×[[[","%"↦"]]]]%[[[["
                 y³F - use this mapping to get the right number of outward brackets on each operation. e.g. "1]+[3]]]×[[[4"
ɓ³i@€Ṁ’x@“[“]”j      - add the right number of brackets to the end to get e.g."[[[1]+[3]]]×[[[4]]]"
               Ç     - this calls the link which evaluates the expression
“+_×:%”Œ!Ç€                          (5a) main link. Input e.g. "1+3×4"
“+_×:%”                                 - the string "+_×:%"
       Œ!                               - all permutations
         Ç€                             - apply link (4) to each permutation
```
The links are evaluated with this (I could probably improve with a different structure):
```
⁾[]i$€Ḥæ%3+\¬œp¹Ḋ€      (1) Helper link: Outputs a list of expressions within brackets, e.g. "[[[1]+[3]]]×[[[4]]]"↦"[[1]+[3]]","[[4]]"
⁾[]i$€Ḥæ%3                 - map "[" to 2, "]" to -2, and any other character to 0.
          +\¬              - cumulative sum negated: 1s at characters not in brackets (includes opening brackets), 0s otherwise (includes closing brackets)
             œp¹           - partition the input, not including borders, based on the sum to get "[[[1]+[3]]","[[[4]]"
                Ḋ€         - remove opening brackets
ÇµḟØDO%9µÐṀṪɓœṣ⁹,ṚÑj@¥/ (2) Return the input to this link with one of the expressions from (1) evaluated
ÇµVṾµ1ĿFḟØDḟ”-Lµ?ÐL     (3) link called from part 1: Evaluates expressions
 µ  µ          µ?          - if:
     1ĿFḟØDḟ”-L            - the input contains no operators within brackets:         
  VṾ                         - evaluate this one expression with normal Jelly calculation and return to string
                           - otherwise:
Ç                            - evaluate one subexpression using link (2)
                  ÐL       - repeat this until a single output is determined
```
The difference between the maximum and minimum is computed with the code in link (5):
```
µṾL_L’ỊµÐfV€ṢIS (5b) determine difference between minimum and maximum
µ      µÐf        - filter out outputs involving division or modulo by 0. Determined with:
 ṾL_L’Ị           - actual numbers have their unevaled form Ṿ no more than one byte longer than the non-unevaled form.
          V€      - evaluate each of these valid numbers to get integers from strings
            Ṣ     - sort
             IS   - return the sum of all difference between consecutive elements.
```
[Answer]
# [Python 2](https://docs.python.org/2/), 235 234 233 226 bytes
-1 byte (and a fix) thanks to [Anders Kaseorg](https://codegolf.stackexchange.com/users/39242/anders-kaseorg)!
-7 bytes thanks to [Step Hen](https://codegolf.stackexchange.com/users/65836/step-hen)!
```
from itertools import*
def f(e,a=()):
 for o in permutations("+-*/%"):
	l=e[:]
	for c in o:
	 for i in range(len(l),0,-1):
		if l[i-1]==c:l[i-2:i+1]=["("+l[i-2]+l[i-1]+l[i]+")"]
	try:a+=eval(*l),
	except:0
 print max(a)-min(a)
```
[Try it online!](https://tio.run/##PVDRboMwDHyGr7CQECGBFdqu6iLxJYiHiCVbppBEIZ3o1zOHSnuI7Dvf2Y79M347e953FdwCOsoQnTMr6MW7EGn@KRUoIhsxkLrmOSgXwIG24GVYHlFE7exKCtbSU1mgIDODHPmUZ0k4J6FD8rDphIKwX5IYaYmpm65p@@TJtAIz6rafhmHmKTtzzRCNBbY@8MReghQmVtQFjojhyQUb5K8whGK7PJPbLH3kXQ4@aBthERsRdbtoi2FPS8jNpzXG6gMo3IFBDy1cqwaqHsEFyX/Qp@SO5dsho9Al4tbBCY0lPoqVEq4Y36sJv/GaiRPezM9jjeTSpZ3wesis3uiIJ9z/AA "Python 2 – Try It Online")
[Answer]
# Haskell 582 bytes
This didn't go nearly as well as I hoped it would...
```
import Data.List
f x=case x of '+'->(+);'-'->(-);'*'->(*);'/'->div;_->rem
e _ s[]=s
e 1 s(')':x:a)|0<-(read$e 0""a),(x=='%'||x=='/')=""|""<-(e 0""s)=""|""<-(e 0""a)=""|0<3=show$(f x)(read$e 0""s)$read$e 0""a
e 1 s")"=e 0""s
e n s(')':a)=e(n-1)(s++")")a
e 0 s('(':a)=e 1 s a
e n s('(':a)=e(n+1)(s++"(")a
e n s(x:a)=e n(s++[x])a
n?s=take n$cycle s
a!b=e 0""(9?"("++(concat$zipWith(++)a(b++[[]]))++9?")")
c#b|l<-[read x|x<-map(c!)(a b),x/=""]=maximum l-minimum l
a c=transpose$map(\x->map((\(Just q)->q).lookup x)$map(\a->zipWith(\x y->(y,x?")"++y:x?"("))[1..5]a)$permutations"+-*%/")c
```
[Try It Online!](https://tio.run/##dVFNb@IwEL3nV0zdoHhiDEH9UEsJvexptfc9hKgaQioi8tXY7JpV/ju1CUjVikYa@Xnee@NnZ0tql5fl8VhUbdNp@EGaJr8Kpb13MHFGKgcDzTsEIpBLLvAlkA5IC0IHQgumFmyKPy9vctnllZfDG6gkjZVFM1A8wGBu5oR9tJC8y2nj5xAxRjjmJo6DUdD3bp0GGDPWM2ZVJ4H6b0@nfbS4i9W2@etzGxC/zFPofxk@nM2QxQNp9/U5i52T81rOkCshrAKdOHIkH0jnBLo4@MUhzg4@OBxpBn3t@olJbb9@VbGmne352SErc1Ae3ayHEPz51ZqF4FlTZ6T9f0X7u9BbLgQSX9sJSZoiCmFlNpWX3a77ciETdyswvVnIilqe3SAnWOPYTO1zpHFFpqj2FZSyKuoBeQRZrDuqVduo3HeulZFLt/IV/7lXGj5QLj9wUjbNbt/adxxEJJeXTCsDB/t7D2PjwghxmBsXHjGZTSYPKaHf5l2116SLplZMyHA0ZZgdKypqiGHTeGC/titqDT7wW4SEPbMxe7I1s3XPUmChkOyKzvF3F40Iv5PMTvQ11h3yeD4ocip5fcpjdE50MdzbenCG6Sgchez4CQ)
Trying to golf a long program just makes me write bad code :(
I tried to use Anders' algorithm in Haskell, but it got out of my control
The function e is like a specific case of eval. (#) takes a list of strings representing integers and a string of operators and returns the difference between the maximum and minimum possible values. e.g
```
(#) ["9","8","1","4"] "*+-" => 32
```
[Answer]
# [Haskell](https://www.haskell.org/), 254 bytes
```
import Data.List.Split
import Data.List
f s=(-)<$>maximum<*>minimum$permutations(zip"+-*/%"[p(+),p(-),p(*),c$div,c$mod])>>=(s!)
p=((pure.).)
c o a b=[o a b|b/=0]
s![]=[read s]
s!((x,o):y)=case splitOn[x]s>>=(!y)of[]->[];l->l?o
[a]?_=[a]
(a:b)?o=b?o>>=o a
```
[Try it online!](https://tio.run/##XU7LTsMwELznK6ZRK9lpkraiVCXUyYULEogDR2NVTpsKi/ihOEUt4t@Dw4EDh53dmZ19vEv/0bTtMCjtbNfjQfYyf1K@z19dq/rovxyd4BnJ6G5aanlR@qx3SamVGaupazp97mWvrPHkS7l4niWLWcwdmdPUhakACU0P06P6DKjtUdCyZMRPaOQYIe7cNTnNaXSAhUTN@G/6rhdsKSI/4YLxrpFH@JERckktLa6UHaRv4Md/Xwy/CD/unFypPXGRlVzct1nZVjbiUlR7FjAisqhpZVld2eANRwYtlQGDlu55D/JmkJVwnTI9iElxgkFR4NH0lIIjvkOCLeZYIcM6ThGvArkJ4h9ZjcU2tDe/tgTLUdgssQiDsxBJ6MywDvk2hhh@AA "Haskell – Try It Online")
Input is a whole string, such as 4+5 \* 2. It generates all permutations of operations, and for each permutation splits the string recursively. It filters divisions by 0 with the list monad.
[Answer]
# Pyth, 45 bytes
```
KS.nm.x.vj\ u.nm+*H/kHckHGd]s.iFQY.p_{eQ-eKhK
```
I'm sure that a lot more optimization can be done, but I like it so far.
Takes input like this: `[9, 8, 1, 4], ["*", "+", "-"]`.
[Try it online!](https://pyth.herokuapp.com/?code=KS.nm.x.vj%5C+u.nm%2B%2aH%2FkHckHGd%5Ds.iFQY.p_%7BeQ-eKhK&input=%5B2%2C+3%2C+10%2C+5%5D%2C+%5B%22%2a%22%2C+%22%2a%22%2C+%22-%22%5D&test_suite=1&test_suite_input=%5B9%2C+8%2C+1%2C+4%5D%2C+%5B%22%2a%22%2C+%22%2B%22%2C+%22-%22%5D%0A%5B1%2C+3%2C+4%5D%2C+%5B%22%2B%22%2C+%22%2a%22%5D%0A%5B1%2C+1%5D%2C+%5B%22%2B%22%5D%0A%5B8%2C+6%2C+1%2C+0%5D%2C+%5B%22-%22%2C+%22%2B%22%2C+%22%2a%22%5D%0A%5B60%2C+8%2C+8%2C+6%2C+4%2C+5%5D%2C+%5B%22%2F%22%2C+%22%25%22%2C+%22%2a%22%2C+%22%25%22%2C+%22%2a%22%5D&debug=0)
[Answer]
# Mathematica, ~~186~~ ~~164~~ 159 bytes
```
eMax@#-Min@#&[Fold[#//.{m___,x_,#2[[0]],y_,n___}:>{m,x~Last@#2~y,n}&,e,#]&/@Permutations@{"+"@Plus,"-"[#-#2&],"*"@Times,"/"@Quotient,"%"@Mod}/. 0/0|1/0->{}]
```
`\[Function]` takes 3 bytes.
Some alternatives (keeps bytecount the same)
`#2-#&@MinMax[...]` to replace `Max@#-Min@#&[...]`
`Head@#2` to replace `#2[[0]]`
Try it online at <http://sandbox.open.wolframcloud.com> : enter `( .... )[{60, "/", 8, "%", 8, "*", 6, "%", 4, "*", 5}]` with `....` replaced by code above for test case `60 / 8 % 8 * 6 % 4 * 5`. Press `Shift + enter` to evaluate.
[Answer]
# Javascript, 280 bytes
**Note**: The integer division rounds using the floor function, which means that negative numbers round away from zero.
This solution is based on [this answer](https://codegolf.stackexchange.com/a/131574/70894).
```
b=>(Math.max(...(f=(a,h="(",i=")",r=[...a[d="replace"](/[^-+*/%]|(.)(?=.*\1)/g,"")])=>(r[0]?(r.map((c,j)=>s=s.concat(f(h+a[d](RegExp("\\"+(n=r.concat()).splice(j,1),"g"),i+c+h)+i,h+"(",i+")",n)),s=[]),s):(a=eval(`(${a})`[d](/\(/g,"Math.floor(")))==a&&1/a?a:r))(b))-Math.min(...f(b)))
```
Example code snippet:
```
g=
b=>(Math.max(...(f=(a,h="(",i=")",r=[...a[d="replace"](/[^-+*/%]|(.)(?=.*\1)/g,"")])=>(r[0]?(r.map((c,j)=>s=s.concat(f(h+a[d](RegExp("\\"+(n=r.concat()).splice(j,1),"g"),i+c+h)+i,h+"(",i+")",n)),s=[]),s):(a=eval(`(${a})`[d](/\(/g,"Math.floor(")))==a&&1/a?a:r))(b))-Math.min(...f(b)))
for(k=0;k<5;k++)
  v=["9*8+1-4","1+3*4","1+1","8-6+1*0","60/8%8*6%4*5"][k],
  console.log(`g(${v}) = ${g(v)}`)
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~262~~ ~~256~~ 254 bytes
```
from itertools import*
def r(s,o):
 try:
  while o in s:i=s.index(o)-1;s[i:i+3]=[`eval(''.join(s[i:i+3]))`]
  return s
 except:0
def f(s):
 u=[int(v[0])for v in [reduce(r,O,s.split(' '))for O in permutations('*/%+-')]if v!=None];return abs(max(u)-min(u))
```
[Try it online!](https://tio.run/##ZU5BboMwEDyXV2wPyDaBBJo0SonopffmAQgpNFkUV2Ajr6Hk9dSgtkrUw@5KM7Mz017tRauncayMbkBaNFbrmkA2rTY28M5YgeEUapF6YM3Vbfi6yBpBg1RAqcxoKdUZB65FlOwpl6lcrIssP2Jf1pyx5aeWiv/iQhwLZ2HQdsa9e4DDCVubxnNSxWnK6bJcKsv7PC5EpQ30U1Ru8NydkJvwENKS2lpazoCJWXGYFC2aprOllVoRZ8HKX0RMFLKC/jF71wqL/U9s@UG8KQfeiahx3TohxindItm3knAu8dAa1wEoZNkrC6dinvcnYC8QwA4WkEAEGyZumMSha8f@R5M7ZOc@t7NDAPEds41h5cx9N4GT@LBx95mJ8Rs "Python 2 – Try It Online")
[Answer]
# [PHP](https://php.net/), 316 bytes
```
<?for(;$t++<54322;)count_chars($t,3)!=12345?:$p[]=$t;foreach($p as$x){for(list($z,$q)=$_GET,$b=1,$i=0;$y=strtr($x,12345,"/%*+-")[$i++];)while(-1<$k=array_flip($q)[$y]){$n=$k+1;if($b&=$z[$n]||ord($y)%10<6)eval("\$z[$k]=$z[$k]$y$z[$n]^0;");($s=array_splice)($z,$n,1);$s($q,$k,1);}$b?$r[]=$z[0]:0;}echo max($r)-min($r);
```
[Try it online!](https://tio.run/##PZBNT8MwDIbv@xUjeChZM9HuS2hptAOaEBe47BZC1ZWORu3aLA2w7oO/Ptpu4vDqtWX7kW2d6LM/14nuxMYUJjCxLoxV@Sf@XQQvr8vnxwVhHQieFksuBJq6iKKHq6a1xrUmSFKB7uuoV6v/71Ky87owmIF1HH8yHg2HjETFV26DKAlNicHSEbnh3nA0nsxnoIXkYFk9EodRgkF3wxJ25NAwMlVaDHsKW8LbbSisuEdBcZdBxUtrrMGwoy2Lovte3xkgIkA5jmTkJ1FZjAeeDykPjQmrYJ0pjWuYgEqSA@QcUsdjao1hdcdhLyCXx2NhPjBUpOe5/pTE32GG0VtTSyW/GFSX1neXIcIwlFd6qTMVxaRdOKceYVAfu6WQNvEJVnMwomW4cuayUxwlRXcT7jAYMtiovHF2vtVG1a8yl@wP "PHP – Try It Online")
```
Expanded
for(;$t++<54322;)
  count_chars($t,3)!=12345?:$p[]=$t;
foreach($p as$x){
  for(list($z,$q)=$_GET,$b=1,$i=0;$y=strtr($x,12345,"/%*+-")[$i++];)
    while(-1<$k=array_flip($q)[$y]){
      $n=$k+1;
      if($b&=$z[$n]||ord($y)%10<6)
        eval("\$z[$k]=$z[$k]$y$z[$n]^0;");
      ($s=array_splice)($z,$n,1);
      $s($q,$k,1);
    }
  $b?$r[]=$z[0]:0;
}
echo max($r)-min($r);
```
[Answer]
# JavaScript (ES6), 210 bytes
Input as an array of numbers and operators
```
k=>(m=n=-k,r=(o,k,j=0)=>{for(o||(m=m>k?m:k,n=n<k?n:k);q=o[j++];(q>'%'&q<'/'||z)&&r(o.slice(0,j-1)+o.slice(j),h))for(h=[...k],z=1;i=h.indexOf(q)+1;h.splice(i-2,3,eval(a=h[i-2]+q+h[i])|0))z*=h[i]})('+-*/%',k)|m-n
```
*Less golfed*
```
k=>(
  m = n = NaN,
  r =(o, k, j=0) => {
    // try all operators in o
    for(;q = o[j]; j++)
    {  
      // q : current operator, 
      // look for q inside the expression to evaluate
      for(h = [...k], z = 1; i = h.indexOf(q) + 1;)
      {
        a = h[i - 2]
        b = h[i]
        z *= b // trace if any second operand is zero
        // subst subexpression with its value
        h.splice(i - 2, 3, eval(a + q + b) | 0)
      }
      // now all subexp involving current operator are evaluated
      // the result is ok if current operator is not % or /
      //  OR if no second operand was zero
      (q > '%' & q < '/' || z) && 
        // try again recursively
        // using the remaining operators and the remaining expression
        r(o.slice(0, j) + o.slice(j+1), h) 
    }
    // if no more operators to try, check max and min
    // k is an array with 1 element, can be used like a single number
    o || (
      m = m > k ? m : k, 
      n = n < k ? n : k
    )
  },
  r('+-*/%', k),
  m-n
)
```
**Test**
```
var F=
k=>(m=n=-k,r=(o,k,j=0)=>{for(o||(m=m>k?m:k,n=n<k?n:k);q=o[j++];(q>'%'&q<'/'||z)&&r(o.slice(0,j-1)+o.slice(j),h))for(h=[...k],z=1;i=h.indexOf(q)+1;h.splice(i-2,3,eval(a=h[i-2]+q+h[i])|0))z*=h[i]})('+-*/%',k)|m-n
function update() {
  var input = I.value.match(/\d+|\S/g)
  var result = F(input)
  O.textContent = I.value + ' -> ' + result + ' (max:'+m+' min:'+n+')'
}
update()
```
```
<input id=I value="60 / 8 % 8 * 6 % 4 * 5" oninput='update()'>
<pre id=O></pre>
```
[Answer]
# [Python 3](https://docs.python.org/3/), 284 bytes
Edit: seems like something's wrong with evaluating the last example. I'll look into it tomorrow.
Another Python answer. Couldn't outgolf everyone else, but I spent too long on this to not put it up.
```
from itertools import*
def f(n,o):
 z=[]
 for p in permutations("+-*/%"):
  try:
   p,x,a=[*p],n[:],o[:]
   while(p):
    for i,d in enumerate(a):
     if d==p[0]:x[i+1]=str(eval(x[i]+d+x[i+1]));x.pop(i);a.pop(i)
    p.pop(0)
   z+=x
  except:0
 z=[*map(float,z)];return max(z)-min(z)
```
[Try it online!](https://tio.run/##bY/bioMwEIbvfYpBKIkat5buStfik4RchDWhAXMgTXetL@/G1LIU9mL@OX0zmbh7uFhzXBbprQYVhA/WjldQ2lkfymwQEiQ2xBZdBnNPWQbSenCgDDjh9S3woKy54ryqy/0uXzEI/r46cGQivKelY8TQjhEbZa3/XNQosEsspH2KDOtGYW5aeB4E5lsTlISh7x1tWDdRVR1Yfw0ei28@4pizaqge5aI4T2/OOqyKM9@CtMGlpEnJXPVT9GL6Ei50TfpRqbnDcrQ8kLlgZy/CzRvQfMJzUWtlolucVyZgiSn6RATQaZXDKu@IEaB5mRPIq1XqPF6S/fGRQsdoG5iY8h/m8Oy/tuJLqE1tgpqEoDqGVbQSvaJtE4unzdrHcVE@HlP7WNylqaeP08sv "Python 3 – Try It Online")
[Answer]
# [Clojure](https://clojure.org/) (+ combinatorics), ~~342~~ 377 + 41 = 418 bytes
*+35 bytes because of a bug.*
```
(fn[x y](let[l filter s first z #(l(fn[y]y)%)r(sort(z(for[e(q/permutations[+ - * quot mod])](try(loop[t e m y a x](if(=[]t)(s a)(let[j(s t)i(reverse(keep-indexed #(if(= j %2)%)m))](recur(rest t)(l #(not= j %)m)(loop[d 0 h a](if(=(count i)d)h(let[c(nth i d)f(inc c)](recur(inc d)(vec(z(assoc h c(j(nth h c)(nth h f))f nil)))))))))))(catch Exception _ nil)))))](-(last r)(s r))))
```
[Try it online!](https://tio.run/##RVDRasMwDPwVwSiTNlrGHgt73FcEMzxHJs4cO5WVkvTnMycdnR/MWTrdnexi7ifhFYUvUxCG58bdS6fBandyefgOyWqW4AqchT0LnG2Mhlb0qZlhMRhZmwg@RK3NUoEUhRs8Ydwoi1noQIIli@INfZaGcWQZJrUacirNKxzhBS5TVhhya8igyoIx57FRYBhgAQuzweDxozFKWMDS7tpXqBRq@itLYfxhHo8htTxzW/23Aejh8F4DDFR1hd0k9a75qkyslJR1p9T@3bGFN@jA3t3Q5SkpBGqp2w0dJu0gQEseQ3LgHqLbqyW8sqtL2lKyqzIO@32gIvoDnshDCpH@DzqrroPP2fG4/Qh8PQgGjxhtjSvb1rKV1vUX "Try it online")
For this function to work, you have to `use` the `clojure.math.combinatorics` library (41 bytes):
```
(use '[clojure.math.combinatorics :as q])
```
## Nuances:
This function is an anonymous function, which means you must do this to use it:
```
((fn[x y]...) numbers operators)
```
Also, I'm using the word `quot` instead of `/` (since Clojure does fraction division by default), and `mod` instead of `%`.
## Ungolfed program:
```
(defn precedence [numbers operators]
  (let [results
        (sort
          (for [permute (c/permutations [+ - * / mod])]
            (loop [p-temp permute
                  o-temp operators
                  n-temp numbers]
              (if (empty? o-temp) (first n-temp)
                (let [first-p (first p-temp)
                      indices (reverse (keep-indexed #(when (= first-p %2) %) o-temp))]
                  (recur
                    (rest p-temp)
                    (filter #(not= first-p %) o-temp)
                    (loop [ind 0
                          n-through n-temp]
                      (if (= ind (count indices)) n-through
                        (let [current-ind (nth indices ind)]
                          (recur
                            (inc ind)
                            (vec
                              (filter #(not (nil? %))
                                (assoc n-through
                                  current-ind (first-p (nth n-through current-ind) (nth n-through (inc current-ind)))
                                  (inc current-ind) nil)))))))))))))]
    (- (last results) (first results))))
```
]