Solved Problem 2, very crude and inefficient algo though