Completed Problem 6 (Brute Force)