Adding full solution to problem 23