05-24-2005, 07:06 PM

This was one of the problems from programming competition I won this year.

A polyominoe is a connected patch of the same letters, they must be connected directly verticaly or horizontally

A A A B B

A B B B C

A A B C C

D D D D C

D D D A B

the bold A's are an example of a polyominoe

You must write a program to count the number of polyominoes in a grid of letters

you take input from a text file (must be test.dat), i.e:

the first number in the file, x, will be the x size of the grid, the second, y, will be the y size. the next x*y data entrys will be upper case letters (the data for the grid)

the output for this data would be 6

your program should be able to handle grids of capital letters only, with a size maximum of 32x32

the fastest program will win

A polyominoe is a connected patch of the same letters, they must be connected directly verticaly or horizontally

A A A B B

A B B B C

A A B C C

D D D D C

D D D A B

the bold A's are an example of a polyominoe

You must write a program to count the number of polyominoes in a grid of letters

you take input from a text file (must be test.dat), i.e:

the first number in the file, x, will be the x size of the grid, the second, y, will be the y size. the next x*y data entrys will be upper case letters (the data for the grid)

Code:

`5, 5`

A, A, A, B, B

A, B, B, B, C

A, A, B, C, C

D, D, D, D, C

D, D, D, A, B

the output for this data would be 6

your program should be able to handle grids of capital letters only, with a size maximum of 32x32

the fastest program will win