Programming Challenge: Shape detection.

Emerald_Knight
Thu, 08 Nov 2018 21:49:40 +0000

The programming challenges have kind of come to a grinding halt recently. I think it's time to get another challenge started!

Given a grid of symbols, representing a simple binary state of "filled" or "unfilled", determine whether or not a square is present on the grid. Squares must be 2x2 in size or larger, must be completely solid (i.e. all symbols in the NxN space are "filled"), and must not be directly adjacent to any other filled spaces.

Example, where 0 is "empty" and 1 is "filled":

000000
011100
011100
011100
000010

// Returns true.

000000
011100
011100
011110
000000

// Returns false.

000000
011100
010100
011100
000000

// Returns false.

For those who want a greater challenge, try any of the following:

1. Get a count of all squares.

2. Detect squares that are touching (but not as a rectangle).

3. Detect other specific shapes like triangles or circles (you will need to be creative).

4. If doing (1) and (3), count shapes separately based on type.

5. Detect shapes within unfilled space as well (a checkerboard pattern is a great use case).

Comments URL: https://tildes.net/~comp/8c1/programming_challenge_shape_detection

Votes: 13

Comments: 2