Solution for assignment 2, plus tests and an alternative solution.