What's great about golfing is not having to deal with errors. Except this time you won't get off so lightly! I need to do some arithmetic with certain limitations, and I wan't to know what goes wrong if anything.
Challenge
Given a list of signed integer values [n1..n11]
, give the following result or the first error that occurred.
(((((((((n1+n2)-n3)^n4)/n5)*n6)+n7)-n8)^n9)/n10)*n11
The same in reverse polish notation:
n1 n2 + n3 - n4 ^ n5 / n6 * n7 + n8 - n9 ^ n10 / n11 *
The operators have the following limitations:
0^0
→ error0^0 is undefined
0^a
whena<0
→ errorNegative exponent
a/0
→ errorDivision by zero
a/b
whenmod a b != 0
→ errorUneven division
- for any operator:
result < 0
→ errorInteger underflow
- for any operator:
result > 99
→ errorInteger overflow
- for any operator: either input value or result == 13 → error
13 is bad luck!
Errors occur left to right, so 13/0
= error 13 is bad luck!
.
Scoring
The shortest code in bytes wins. To encourage readability string literals used for errors won't count towards the score.
The output format isn't strict but all seven errors plus a correct value must be distinguishable. Your program/function must retain control flow until the end, so e.g. any exceptions must be caught.
Standard loopholes are disallowed.
Examples
[6,7,14,2,0,1,2,3,4,0,6] → error `13 is bad luck!`
[6,6,14,2,0,1,2,3,4,0,6] → error `Integer underflow`
[6,6,12,0,0,1,2,3,4,0,6] → error `0^0 is undefined`
[6,6,12,2,0,1,2,3,4,0,6] → error `Division by zero`
[6,6,10,6,12,1,2,3,4,0,6] → error `Uneven division`
[6,6,10,6,8,17,2,13,4,0,6] → error `Integer overflow`
[6,6,10,6,8,7,99,13,4,0,6] → error `Integer overflow`
[6,6,10,6,8,7,9,99,4,0,6] → error `Integer underflow`
[6,6,10,6,8,7,9,55,-2,0,0] → error `Negative exponent`
[6,6,10,6,8,7,9,56,2,0,8] → error `Division by zero`
[6,6,10,6,8,7,9,56,2,9,12] → error `Integer overflow`
[6,6,10,6,8,7,9,56,2,9,11] → 99