Defining a Perplexing Two-Dimensional Sequence Explicitly
This is a question taken from R. Creighton Buck's Advanced Calculus, Third Edition. It is exercise 5 in Section 1.6 (page 54), which is a starred (challenge) problem. "Starting at the origin in the plane, draw a polygonal line as follows: Go 1 unit east, 2 units north, 3 units west, 4 units south, 5 units east, 6 units north, and so on. Find a formula for the $n$th vertex of this polygon."
The sequence of points is $\{(1,0),\,(1,2),\,(-2,2),\,(-2,-2),\,(3,-2),\,\dots,\,(x_n,y_n)\}$. I decided to find an explicit definition for the $n$th vertex. I started by cracking the sequence of $x$ values, $\{1,\,1,\,-2,\,-2,\,3,\,3,\,-4,\,-4,\,\dots\}$ (notice that $x_{2k-1}=x_{2k}$, where all $k\in\mathbb N$). Disregarding the negative signs results in the sequence $\{1,\,1,\,2,\,2,\,3,\,3,\,4,\,4,\,\dots\}$, which can be defined by $|x_n|=\frac{n+1}2$ for odd $n$ and $|x_n|=\frac n 2$ for even $n$. This can be simplified to $|x_n|=\frac{n+\frac{1}2-\frac{{(-1)}^n}2}2$ for all $n$, which can be further simplified to $|x_n|=\frac{2n+1-{(-1)^n}}4$. In order to get back to the original sequence $x_n$, $|x_n|$ must be multiplied by $(-1)^m$, where $m$ is an expression in terms of $n$ such that $(-1)^m$ produces the sequence $\{1,\,1,\,-1,\,-1,\,1,\,1,\,\dots\}$. One could find a completely different expression, but $m$ could simply be $|x_n|+1$.$$(-1)^m=(-1)^{|x_n|+1}=(-1)^{{\frac{2n+5-(-1)^n}4}}$$$|x_n|+1$ produces $\{2,\,2,\,3,\,3,\,4,\,4,\,\dots\}$, so $(-1)^{|x_n|+1}$ does indeed produce the sequence $\{1,\,1,\,-1,\,-1,\,1,\,1,\,\dots\}$. Therefore,$$x_n=(-1)^{{\frac{2n+5-(-1)^n}4}}\left(\frac{2n+1-(-1)^n}4\right).$$Now all that remains is finding an explicit definition for the sequence of $y$ values, $\{0,\,2,\,2,\,-2,\,-2,\,4,\,4,\,-4,\,-4,\,\dots\}$. This, however, is where I am stuck. The first approach I tried was $2x_n$, but that produces $\{2,\,2,\,-4,\,-4,\,6,\,6,\,\dots\}$. In fact, I've tried several variations of $x_n$, but none thus far have produced a variation of $\{0,\,a,\,a,\,-a,\,-a,\,2a,\,2a,\,-2a,\,-2a,\,3a,\,3a,\,-3a,\,-3a,\,\dots\}$. Even the back of Buck's book, which gives hints for selected problems, only shows a recursive definition for $(x_{4n+1},y_{4n+1})$. I'm at my wit's end here, any tips on how to proceed?
The function
$$f(n)=\left\lceil\frac{n-1}4\right\rceil$$
gives you the sequence $\langle 0,1,1,1,1,2,2,2,2,3,3,3,3,\ldots\rangle$ for $n\in\Bbb Z^+$. (Here $\lceil x\rceil$ is the ceiling of $x$, i.e., the unique integer $n$ such that $n-1<x\le n$.) Thus, the function
$$g(n)=2\left\lceil\frac{n-1}4\right\rceil$$
handles everything except the algebraic sign. You already know how to take care of the sign (and notice that $0=-0$, so the first term won’t be a problem).
An alternative solution: use the fact that $\sin(\frac{n\pi}{2})$ and $\cos(\frac{n\pi}{2})$ give cyclic values of $1,0,-1,0...$ to get
$$\frac{1}{2} [1-(1+n) \cos(\frac{n \pi}{2})-n \sin(\frac{n \pi}{2})]$$
which directly gives the sequence that you are looking for.