Finds the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in a square grid of any dimension.