solved problem 31, which was the best and hardest problem thus far.