Solution and test for problem 21