wrote a ridiculously more efficient version of problem 2