finally finding solution to problem 49