brute force approach of prob 5, still checking