Notice, first of all, that once you have laid down the chain $A_0 A_1 B_2 A_3 B_4 \dots$ then the other chain is the symmetric of that. If $\alpha$ is the angle at $A_0$, then in isosceles triangle $A_0 A_1 B_2$ we have $\angle A_0 B_2 A_1=\alpha$ and
$\angle A_0 A_1 B_2=\pi-2\alpha$. We thus find that $\angle B_2 A_1 A_3=2\alpha$ and, going on with the same reasoning as before, $\angle A_1 B_2 A_3=\pi-4\alpha$, $\angle A_3 B_2 B_4=3\alpha$, and so on. Hence:
$$\angle A_k B_{k-1} B_k=\angle B_k A_{k-1} A_k=k\alpha.$$
The chain stops if $A_n=A_{n+1}$ for some $n$ ($n=4$ in the figure). But $A_0A_nB_n$ is an isosceles triangle, hence
$\angle B_n A_n A_{n-1}=\angle B_n A_{n-1} A_n=(\pi-\alpha)/2$ and comparing with the above result we get $n\alpha=(\pi-\alpha)/2$, that is:
$$\alpha={\pi\over2n+1}.$$
The answer is
$$\frac{d}{\max\left( |\cos\theta|, |\sin\theta| \right)}$$
To understand why the answer has this form, let us look at a related problem.
Let's say we have a convex $n$-gon with origin in its interior. If we shoot a light ray from origin in direction $\vec{t} = (\cos\theta,\sin\theta)$, how far will the light travel before it hit the boundary?
For the $i^{th}$ edge of the polygon, let $\vec{n}_i = (\cos\theta_i,\sin\theta_i)$ be its outward pointing normal and $d_i$ be its distance to origin. The region bounded by the $n$-gon is
the collection of point $\vec{p} = (x,y)$ which satisfies the inequalities
$$\vec{p}\cdot \vec{n}_i = x\cos\theta_i + y \sin\theta_i \le d_i\quad\text{ for } 1 \le i \le n$$
For a point $\vec{p} = \lambda \vec{t} = \lambda (\cos\theta,\sin\theta)$ on the ray, this becomes
$$ \lambda (\cos\theta\cos\theta_i + \sin\theta\sin\theta_i) \le d_i
\quad\iff\quad \lambda \cos(\theta - \theta_i) \le d_i$$
for all $1 \le i \le n$. Since $\lambda > 0$, this is equivalent to
$$\frac{1}{\lambda} \ge \frac{1}{d_i}\cos(\theta - \theta_i)\;\text{ for all }i
\quad\iff\quad \frac{1}{\lambda} \ge \max_{1\le i \le n}\left(\frac{1}{d_i}\cos(\theta - \theta_i)\right)$$
This implies the light will travel along direction $\vec{t}$ for a distance
$$\Lambda(\theta) \stackrel{def}{=} \frac{1}{\max\limits_{1\le i \le n}\left(\frac{1}{d_i}\cos(\theta - \theta_i)\right)}$$
before it hit the boundary.
Back to problem at hand. If we choose a coordinate system to make the square centered at origin with sides parallel to $x$- and $y$- axis, then
$n = 4$ with $(\theta_1,\theta_2,\theta_3,\theta_4) = (0,\frac{\pi}{2},\pi,\frac{3\pi}{2})$ and all $d_i$ equals to $\frac{d}{2}$. This implies
$$\begin{align}\Lambda(\theta)
&= \frac{d}{2\max\left[
\cos\theta, \cos\left(\theta - \frac{\pi}{2}\right),
\cos(\theta - \pi),
\cos\left(\theta - \frac{3\pi}{2}\right)\right]}\\
&= \frac{d}{2\max(|\cos\theta|,|\sin\theta|)}\end{align}$$
The length you seek is simply
$$\Lambda(\theta) + \Lambda(\theta+\pi) = 2\Lambda(\theta) = \frac{d}{\max(|\cos\theta|,|\sin\theta|)}$$
Best Answer
It is just a simple pythagoras theorem. You find the diagonal of the square $=\sqrt {50}$
Therefore the side of the square is $=5$