Solution for problem 42