I recently came across this problem:
Find a continuous function $f$ with $f(x) \geq 0$ for all $x$ such that $\int_0^\infty f(x)\;dx$ exists as a finite number, but $\lim_{x \rightarrow \infty} f(x)$ does not exist
But the author provides the answer in terms of figure, namely, the following one:

My question is: How to write this function explicitly ?
Any help?
There is of course a good reason that the author uses a graphical representation of the function, because it looks a bit nasty. A straightforward characterisation would use a compound formulation like $$ f(x) = \left \{ \begin{array}{ll} 0 & x<1 \\ 2^n (x-n) & x \in [n,n+\frac{1}{2^n}) \\ 2^n (n+\frac{2}{2^n}-x) & x \in [n+\frac{1}{2^n},n+\frac{2}{2^n}) \\ 0 & x \in [n+\frac{2}{2^n},n+1) \end{array} \right. $$ where $n\equiv [x]$, i.e., the smallest integer less than or equal to $x$.
In this approach you split the curve in strictly linear segments. If you allow the floor function to be used explicitly, the non-zero parts of each unit-length interval can be combined to
$$ f(x) = \left \{ \begin{array}{ll} 1 - 2^{[x]} \left| x - [x] - \frac{1}{2^{[x]}}\right| & x \in [n,n+\frac{2}{2^n}) \\ 0 & x \in [n+\frac{2}{2^n},n+1) \end{array} \right. $$
This can be cast into a "single, closed expression", if you would allow to use the Heaviside step function $\Theta(x)$:
$$ f(x)=\Theta(x-1) \Theta([x] + \frac{2}{2^{[x]}} - x) \left( 1 - 2^{[x]} \left| x - [x] - \frac{1}{2^{[x]}}\right|\right) $$
The first $\Theta$ ensures that the function is zero for $x<1$. The second $\Theta$ makes the function also zero in the intervals $[n+2/2^n,n+1)$. If you substitute the $\Theta$-functions by means of $$ \Theta(y) \equiv \frac{1}{2} + \frac{y}{2 |y|} $$ you would get $f(x)$ in terms of only floor functions. There is the minor problem of having to take the various limits $y \rightarrow 0$, but since the third factor in $f(x)$ would be zero in those cases anyway this can be discarded.