problem 36 can be solved in a more efficient way