unoptimized solution for four
problem 5