#4 Solver for problem 22. Also fixes solver 21