problem 10 solved - needs refactoring as took 3 hours to run