Adding solution to problem 18