finished problem 17, both brute force and *better* method