(brute-force) solution to problem 4