29
0
The three-dimensional Levi-Civita symbol is a function f
taking triples of numbers (i,j,k)
each in {1,2,3}
, to {-1,0,1}
, defined as:
f(i,j,k) = 0
wheni,j,k
are not distinct, i.e.i=j
orj=k
ork=i
f(i,j,k) = 1
when(i,j,k)
is a cyclic shift of(1,2,3)
, that is one of(1,2,3), (2,3,1), (3,1,2)
.f(i,j,k) = -1
when(i,j,k)
is a cyclic shift of(3,2,1)
, that is one of(3,2,1), (2,1,3), (1,3,2)
.
The result is the sign of a permutation of (1,2,3)
, with non-permutations giving 0. Alternatively, if we associate the values 1,2,3
with orthogonal unit basis vectors e_1, e_2, e_3
, then f(i,j,k)
is the determinant of the 3x3 matrix with columns e_i, e_j, e_k
.
Input
Three numbers each from {1,2,3}
in order. Or, you may choose to use zero-indexed {0,1,2}
.
Output
Their Levi-Civita function value from {-1,0,1}
. This is code golf.
Test cases
There are 27 possible inputs.
(1, 1, 1) => 0
(1, 1, 2) => 0
(1, 1, 3) => 0
(1, 2, 1) => 0
(1, 2, 2) => 0
(1, 2, 3) => 1
(1, 3, 1) => 0
(1, 3, 2) => -1
(1, 3, 3) => 0
(2, 1, 1) => 0
(2, 1, 2) => 0
(2, 1, 3) => -1
(2, 2, 1) => 0
(2, 2, 2) => 0
(2, 2, 3) => 0
(2, 3, 1) => 1
(2, 3, 2) => 0
(2, 3, 3) => 0
(3, 1, 1) => 0
(3, 1, 2) => 1
(3, 1, 3) => 0
(3, 2, 1) => -1
(3, 2, 2) => 0
(3, 2, 3) => 0
(3, 3, 1) => 0
(3, 3, 2) => 0
(3, 3, 3) => 0
2Related. – Martin Ender – 2018-03-26T22:24:26.977