add complete solution for problem 18