solution for problem18