# Formula for periodic sequence

Given $n \in \Bbb N$ | $n \gt 0$, I want to map an incrementing input number to a periodic sequence.

$$\left[ \begin{array}{c|cc} x&0&1&2&...&...&...&...&...&...&...&i-1&i\\ y&0&1&2&...&n-1&n&n-1&...&1&0&1&2 \end{array} \right]$$

For $n=2$ it'd look like $$\left[ \begin{array}{c|cc} x&0&1&2&3&4&5&6&7&8\\ y&0&1&2&1&0&1&2&1&0 \end{array} \right]$$

This reminds me of a periodic zigzag sequence (https://oeis.org/A007877), but I can't come up with a general equation for a variable $n$.

Try $y = n-| (x \bmod 2n) - n|$.