Sometimes, when I'm really bored (really bored), I like to draw a line segment and draw points on it.
First, I draw a line segment of a certain size, which is 2^N for some value of N. The line will be represented by a series of .
characters.
................
Then, I plot a point at the left end. Points will be represented by X
characters.
X...............
Then, I follow a pattern. Starting at the most recently plotted point (which I'll call A), I advance to the next plotted point (B) on the line (wrapping around as necessary). Then, I advance to the next plotted point on the line (C). Then, I plot a new point half-way in between this third point (C) and the next already plotted point (D).
Whenever you wrap around the line, the "middle" is determined in wrapping manner. The newly plotted point is always to the right of C.
Let's say that the following line was my current line. Here is how I would plot the next two points. For this example, I'll label each important point with a letter.
X...A...X.X...X.
^
X...A...B.X...X.
^
X...A...B.C...X.
^
X...A...B.C...D.
^
X...X...X.X.A.X.
^
X...X...X.X.A.B.
^
C...X...X.X.A.B.
^
C...D...X.X.A.B.
^
X.A.X...X.X.X.X.
^
Returning to the previous example, the next point will be plotted in the middle of the line.
X.......X.......
This is perhaps a little bit of a special case: advancing to the next point simply leaves you where you started. The only useful halfway point is the "cyclic" halfway point (the halfway point on the line), as opposed plotting a point on top of itself.
Below is the series of points that I would plot on the line from here to the end.
X.......X.......
X.......X...X...
X.......X.X.X...
X...X...X.X.X...
X...X...X.XXX...
X.X.X...X.XXX...
X.X.X...XXXXX...
There is no longer any room to plot the next point, as it would have to be wedged between two adjacent points, so I have reached the maximum depth for the given value of N = 4. The last line in the above list is "complete."
The Challenge
The goal is to write the shortest program/named function that will print/return the completed line for a given value of N. The above shows N = 4.
Input
Input will be a single non-negative integer N. The length of the generated line will then be 2^N.
Output
Output will be the completed line of length 2^N, formed by .
and X
characters. A trailing newline doesn't matter.
Example I/O
0
X
1
XX
2
X.XX
3
X.X.XXX.
4
X.X.X...XXXXX...
5
X.X.X...X...X...X.XXX.XXX.......