Solved problem 7 (kinda efficiently, too!)