naive implementation of problem 8