Solution for problem 51