Solution for exercise DP 3.2