You can condense the part where you get rid of the lowest value to a single line by using the MIN function, which returns the lowest value out of two values you send to it. DMG=R1+R2+R3-MIN(R1,MIN(R2,R3)) As a side note, you can also use the MIN function to find the lowest value in an array.