commented code for problem 18