prob 31 solved with brute force