Problem 6. Suppose $T$ is the period of the function $y=f(x)$. From the condition, we get:

$$
\cos x=f(x)-3 f(x-\pi)=f(x-T)-3 f(x-T-\pi)=\cos (x-T)
$$

Since this equality holds for all $x$, the number $T$ is the period of the function $y=\cos x$, i.e., $T=2 \pi n$, where $n$ is some natural number. From the given equation, we get:

$$
\begin{gathered}
f(x)=3 f(x-\pi)+\cos x=3(3 f(x-2 \pi)-\cos x)+\cos x= \\
=3(3(3 f(x-3 \pi)+\cos x)-\cos x)+\cos x= \\
=\ldots=3(3(\ldots(3 f(x-2 \pi n)-\cos x)+\ldots+\cos x)-\cos x)+\cos x= \\
=3^{2 n} f(x)-\cos x\left(3^{2 n-1}-3^{2 n-2}+3^{2 n-3}-\ldots+3-1\right)
\end{gathered}
$$

Then

$$
f(x)\left(1-3^{2 n}\right)=\cos x\left(1-3+3^{2}-\ldots-3^{2 n-1}\right)=\cos x \cdot \frac{1-3^{2 n}}{1+3}
$$

Therefore, $f(x)=\frac{1}{4} \cos x$.
Answer: $f(x)=\frac{1}{4} \cos x$.