Problem 4 solved (with tests).
Unit test for problem 4.