solution to problem 1
updates to problem 1 solution. Improved efficiency via algorithm change