Average distance between two points lying on boundary of a square 
Calculate the average distance between two points lying on the boundary of a unit square. 

I tried to approach it in the same way that this video does, but I couldn't really wrap my head around how not to include the points lying inside the square.
 A: Without loss of generality is sufficient to fix the first point on the bottom side for example, the second contributes from the same side, the upper one - and by symmetry two times from the side ones. Let the side has length $1$ with corners on $(0,0), (0,1), (1,0), (1,1)$ respectively. Hence, the average distance $\bar{w}$ is
$$\bar{w}=\frac{1}{4}\left(I_{\text{bottom}}+I_{\text{upper}}+2I_{\text{sides}}\right)=\\\frac{1}{4}\int_{0}^{1}\int_{0}^{1}\left(|x-y|+\sqrt{(x-y)^2+1}+2\sqrt{(x-1)^2+y^2}\,\right)\mathrm{d}y\,\mathrm{d}x$$
This integral can be computed via hyperbolic substitutions (you can also use similar trick in the video to reduce it to just one integral), the result is according to Mathematica:
$\bar{w}=\frac{1}{12}\left(3+\sqrt2+5\operatorname{arcsinh}{1}\right)=0.735090124789234181247061279092388301975872793\dots$
A: I used Excel to solve this old question, rather than the exact integral by Machinato. There are 3 cases:

*

*the 2 random points could be on the same side of the square (avg dist=0.33,excel),

*the 2 points could be on adjacent perpendicular sides (avg dist=0.76, excel), or

*the 2 points could be on parallel sides (avg distance=1.08, excel)

weighted avg distance=(1* case1 + 2* case2 + 1* case3)/(1+2+1)=0.74
Explanation of weighting: pick a random point on the square, the second point has double the probability of being on an adjacent perpendicular side compared to being on a parallel side or on the same side as the first point.
The analytical Mathematica answer by Machinato is 0.735.
To 2 significant figures, the two answers match, as they should.
Interestingly, the guesstimate of half the diagonal(the maximum distance)=sqrt(2)/2= 0.707 is quite close to the correct answer.
