Solve problem 12 (slowly)