#6 Solver for problem 24