Solved problem 31 using way too many nested conditionals