Adding solution for problem9, even though it runs in about n^3 time...