adding solution to problem 18