problem 9

brute force non efficient solution