Plus or minus polyglots!
Python 2 / 3, 52 bytes
lambda l:sum(l[:1]+[x*int(1-(1/2)*4)for x in l[1:]])
int(1-(1/2)*4)
returns 1
in Python 2 because 1/2
evaluates first to 0
, and then 0 * 4 = 0
.
int(1-(1/2)*4)
returns -1
in Python 3 because 1/2
evaluates first to 0.5
, and then int(0.5 * 4) = int(2.0) = 2
.
C and C++ (both from GCC), 81 75 73 bytes
int c;int f(int*a,int l){auto d=.5;c=*a++;for(;--l;a++)c+=*a-4*d**a;c=c;}
Takes a pointer to array and length.
Explanation: still using @Steadybox' explanation :p In C, auto d=.5
declares an integer variable with the auto storage class (which is the default), which is then initialized to 0, whereas in C++11 it declares a double, which is initialized to 0.5.
C - plus language: Try it online!
C++ - minus language: Try it online!
Jelly / 05AB1E, 3 bytes
00000000: c6 71 53 .qS
This is a hexdump (xxd) of the submitted program.
Try it online!
Jelly: Sum
Jelly uses the Jelly code page, so it sees the following characters.
İqS
Try it online!
How it works
İqS Main link. Argument: A (array)
İ (ignored)
q Unrecognized token. This breaks the link; nothing to the left is executed.
S Take the sum of A.
05AB1E: Difference
05AB1E uses Windows-1252, so it sees the following characters.
ÆqS
Try it online!
How it works
Æ Take the difference of the input.
q Quit.
S (ignored)