problem 8 solved programatically