I know that the solution for the diffusion equation for a general initial condition $u(x,0)=f(x)$ can be given in the form
$$u(x,t)= \frac{1}{\sqrt{4πDt}} \int_{-\infty}^{\infty}f(y)e^{\frac{-(x-y)^2}{4Dt}}dy$$
How do I find an explicit form for this solution when $f(x)=1$ for $x$ between $0$ and $a$, and $0$ otherwise? I was thinking maybe via changing the variables, but didn't reach much further...
It would be helpful if the solution was in terms of the error function $\operatorname{erf}(x)$.
This answer is very close to what you're looking for. See if you can follow through it.