Dylan's solution for problem 1