A closed expression for this sequence of integers Say we have $a_k=n-p$ for $n,p \in \mathbb{Z}_{+}$ where $n-p >0$ and $a_1=n-p-1$, and in general:
$a_k=n-p$
$a_1=n-p-1$
$a_{k-1}=n-p-2$
$a_2=n-p-3$
$a_{k-2}=n-p-4$
$a_{3}=n-p-5$
$\vdots$
and so on. The idea is that if the sequence $(a_1,a_2,...,a_k)$ is ordered from greatest to smallest, we have $(a_k,a_1,a_{k-1},a_{2},a_{k-2},a_3,...)$ where all the numbers are consecutive.
I want to find a general closed expression for $a_i$ for $i\in\{1,...,k\}$, but I cannot seem to find a way to come up with it.
 A: It is convenient to split the problem into two cases with even and odd $k$. Here we consider the case $k=2K$ even:
\begin{align*}
\left(a_j\right)_{1\leq j\leq 2K}=\left(a_1,a_2,\ldots,\color{blue}{a_K,a_{K+1}},\ldots,a_{2K}\right)
\end{align*}
We list the elements $a_j, 1\leq j\leq k=2K$ in a detailed way to better see what's going on. We obtain
\begin{align*}
\begin{array}{ll}
\qquad a_{2K}\ \ \ =a_k\quad=n-p&\qquad\qquad\; a_1=n-p-1\\
\qquad a_{2K-1}=a_{k-1}=n-p-2&\qquad\qquad\; a_2=n-p-3\\
\qquad a_{2K-2}=a_{k-2}=n-p-4&\qquad\qquad\; a_3=n-p-5\\
\qquad\quad\quad\ \ \  \vdots\qquad&\qquad\qquad \quad\ \ \;\vdots\\
a_{2K-(K+1)}=a_{k-(K-1)}=n-p-2(K-1)&\qquad\qquad a_K=n-p-(2K-1)\\
\qquad\qquad\ =a_{K+1}\quad\ \ =n-p-2K+2&\qquad\qquad \quad\  = n-p-2K+1
\end{array}
\end{align*}

From the list above we obtain for $\left(a_j\right)_{1\leq j\leq k}=\left(a_j\right)_{1\leq j\leq 2K}$:
\begin{align*}
\color{blue}{a_j}&=
\begin{cases}
n-p-2j+1&\qquad\quad\ \ \ \;1\leq j\leq K\\
n-p-2K+2(j-K)&\qquad K+1\leq j\leq 2K
\end{cases}\\
&\,\,\color{blue}{=
\begin{cases}
n-p-2j+1&\qquad\qquad\qquad\quad 1\leq j\leq K\\
n-p-4K+2j&\qquad\qquad\quad K+1\leq j\leq 2K
\end{cases}}
\end{align*}

The odd case can be obtained similarly.
A: Firstly, I thought it would be helpful to find a closed form for $\min(x,y)$. This is not so difficult to guess. It is:
$$\min(x,y) = \frac{x+y-|x-y|}{2}$$
which you can verify in each case.
Then, your sequence is described by:
$$a_j = n-p-q$$
where $q = 2\min\bigg((k-j), (j-\frac{1}{2})\bigg)$.
Using the formula above, we derive the closed form:
$$a_j = n-p- \Bigg(k-\frac{1}{2} - \frac{\big|2k-4j+1\big|}{2}\Bigg).$$
