Problem 160 - solution to test cases