Editorial for Wesley's Anger Contest 2 Problem 3 - Pumpkin Counting
Submitting an official solution before solving the problem yourself is a bannable offence.
There are multiple ways to efficiently count the pumpkins. We'll describe one of such methods below.
First, observe that a pumpkin is represented as a patch of black and white pixels. We can go through the grid and find all patches of connected pixels (two pixels are connected if they share at last one corner). One way to find all such patches is using a breadth first search and returning the coordinates of the patch.
For every one of the patches we can generate a pumpkin with the same size as the patch. If the pixels match, then the patch is a valid pumpkin. Careful attention must be given to check if the size of the pumpkin is a positive integer.