Generate triangular signal Task:

Given sample index, x, calculate sample value f(x) of triangular wave, with period of 4 samples and amplitude 1. Offset can be negative and sample value could be either {0, 1, -1}.

Test cases:

   -5 -&gt; -1
   -4 -&gt; 0
   -3 -&gt; 1
   -2 -&gt; 0
   -1 -&gt; -1
    0 -&gt; 0
    1 -&gt; 1
    2 -&gt; 0
    3 -&gt; -1
    4 -&gt; 0
    5 -&gt; 1


Personally I know two approaches in C - the first is using lookup table, the second is using conditional instructions. For brownie points, could you impress me with a pure "math" approach? (I mean a pure functional approach, e.g. not using conditional instructions or using memory for LUT.) But this is not an restriction. If you can't, or your language does not support it - just post any solution
Mathematica, 8 bytes

Im[I^#]&amp;


Explanation

Im[I^#]&amp;
   I^#    (* Raise the imaginary unit to the input power *)
Im[   ]   (* Take the imaginary part *)