Found a pattern for problem 3