Probability --- segments 
*

*Inside a line segment $E$ with length $6$ unit, there are $2$ segments $A$ with length $2$ unit and $B$ with length $3$ unit.

*The  position of  $A$  is fixed  with  its  left  end  being  $k$  unit  from  the  left  end  of  $E$. Thus  the  distance  between  their  right  ends  will  be $\left(\,4 - k\,\right)$ unit,while  $B$  can  move  freely  and  uniformly  inside  $E$.

*If  a  point  is  chosen  randomly  on  $E$ , find  the  probability  that  the  point  lies  inside  $A$  and  $B$  at  the  same  time.

 A: Take left-hand end to have coordinate 0 and right-hand end to have coordinate 6. Let $b$ be the coordinate of the left-hand end of $B$. So $b$ is uniformly distributed on $[0,3]$.
Let the point $X$ have coordinate $x$, so $x$ is uniformly distributed on $[0,6]$. 
$X\in B$ iff $x\in[b,b+3]$, and $X\in A$ iff $x\in[k,k+2]$. So for $b\in[-3,k-3]$ we have $A\cap B=\emptyset$. For $b\in[k-3,k-1]$ we have $A\cap B=[k,b+3]$. For $b\in[k-1,k]$ we have $A\cap B=A$. For $b\in[k,k+2]$ we have $A\cap B=[b,k+2]$ and for $b\in[k+2,6]$ we have $A\cap B=\emptyset$.
Case 1: $k<1$. $18p(x\in A\cap B)=\int_0^k2\ db+\int_k^{k+2}(k+2-b)\ db=2(k+1)$.
Case 2: $1\le k<3$. $18p(x\in A\cap B)=\int_0^{k-1}(b+3-k)db+\int_{k-1}^k2\ db+\int_k^3(k+2-b)db=-k^2+4k+1$
Case 3: $3<k\le4$. $18p(x\in A\cap B)=\int_{k-3}^{k-1}(b+3-k)db+\int_{k-1}^32\ db=2+8-2k=10-2k$

$\textbf{Comment}$
Piecewise functions are fiddly and it is easy to make mistakes. So one needs to do some basic checking. (1) Is the result continuous? (Answer: yes), (2) Does the graph look plausible (no obvious odd wiggles etc) (Answer: yes), (3) Does it respect any obvious symmetries in the problem? (The obvious symmetry here is that the probability should be the same for $k=2\pm h$, which it is.)
