Adding problem 12 - correct but extremely slow, needs reworking