naive brute force attempt for problem 2d, keeping for reference