Let $ {p}_{1} \left(t\right)$ and $ {p}_{2} \left(t\right)$ be the positions
of two consecutive bugs on the $n$-gon. Let $ s \left(t\right)$ be the
distance travelled by bug 1 since the beginning and let $ d \left(t\right) = \left\|{p}_{2} \left(t\right)-{p}_{1} \left(t\right)\right\|$ be the distance between the
two bugs.
One has
\begin{equation}{s'} \left(t\right) = \left\|{{p'}}_{1} \left(t\right)\right\| \qquad {d'} \left(t\right) = \left({{p'}}_{2} \left(t\right)-{{p'}}_{1} \left(t\right)\right) \cdot \frac{\left({p}_{2} \left(t\right)-{p}_{1} \left(t\right)\right)}{\left\|{p}_{2} \left(t\right)-{p}_{1} \left(t\right)\right\|}\end{equation}
Hence $ {d'} \left(t\right)$ is the projection of $ {{p'}}_{2}-{{p'}}_{1}$ onto the line joining $ {p}_{1}$ and $ {p}_{2}$
(a side of the $ n$-gon).
It follows that
\begin{equation}{d'} \left(t\right) = \left(\cos \left(\frac{2 {\pi}}{n}\right)-1\right) \left\|{{p'}}_{1} \left(t\right)\right\| = \left(\cos \left(\frac{2 {\pi}}{n}\right)-1\right) {s'} \left(t\right)\end{equation}
When the bugs meet up, we have
\begin{equation}{-\ell } = d \left(t\right)-d \left(0\right) = \int_{0}^{t}{d'} \left(u\right) d u =-\left(1-\cos \left(\frac{2 {\pi}}{n}\right)\right) s \left(t\right)\end{equation}
The distance travelled by each bug is
\begin{equation}\boxed{s = \frac{\ell }{1-\cos \left(\frac{2 {\pi}}{n}\right)}}\end{equation}
Complete trajectory
We can give a complete parametrization of the bugs' trajectories by
using complex numbers. Let $ {\theta} = \frac{2 {\pi}}{n}$ and
$ {\omega} = \cos {\theta}+i \sin {\theta}$. Let
\begin{equation}{z}_{k} \left(t\right) = \frac{\ell }{\left|{\omega}-1\right|} {e}^{\left({\omega}-1\right) t} {{\omega}}^{k} , \qquad k = 0 , \ldots , n-1\end{equation}
Clearly, these $n$ complex numbers form a $n$-gon centered at
$0$ and one has
\begin{equation}{{z'}}_{k} = \frac{\ell }{\left|{\omega}-1\right|} {e}^{\left({\omega}-1\right) t} {{\omega}}^{k} \left({\omega}-1\right) = {z}_{k+1}-{z}_{k}\end{equation}
which means that $ {z}_{k}$ moves instantly towards
$ {z}_{k+1}$, and
when $ t = 0$ we have $\left|{z}_{k+1}-{z}_{k}\right| = \ell $.
It follows that $ {z}_{k} \left(t\right)$ is a parametrization of the trajectories
of the bugs. The bugs meet when $ t = \infty $ and we have directly
the distance travelled
\begin{equation}s = \int_{0}^{\infty }\left|{z'} \left(t\right)\right| d t = \ell \int_{0}^{\infty }{e}^{\left(\cos {\theta}-1\right) t} d t = \frac{\ell }{1-\cos {\theta}}\end{equation}
Best Answer
According to his son Jim, the favorite puzzle of Martin Gardner was The monkey and the coconuts: