Blob Counting

Given an 8x8 grid and then randomly designating them as either black or white can create 0 or more blobs.
But what is a blob? Given any black filled square in the grid, a blob is the collection of all the black squares adjacent to the current square and adjacent to the squares adjacent to the current square, so on and so forth. Please look at the sample below.


Grid containing 3 blobs.

The grid above contains 3 blobs highlighted by the red lines. The program you will create will count the total number of blobs in a given grid and also count the number of squares a certain blob occupies. The grid will be describe using an input from a text file containing zeros and ones, a “1” signifying black and white otherwise. After reading the file, the application should automatically calculate the total number of blobs and the size of a given blob. A blob will be specified using mnemonics, i.e A0. Back to the sample grid above, the size of the blob should be one since the blob located at the uppermost left corner occupies 1 square.


Console Output:

C:> blob grid.txt A1
Total : 3 blob(s)
Size : 0


Contents of Grid.txt


10000000
00001000
00011110
00111100
00011000
00010000
11000110
11111111

0 comments: