# Perimeter searching a Matrix

## Recommended Posts

I'm wondering if anyone can shine a light as to how I might be able to do this.

The idea is, I have an 8x8 matrix of numbers (1-7). The matrix must be searched for identical numbers next to eachother (either horizontally or vertically). When a pair is found, the area around each number (not diagonally) must be searched for the same number (ie. a pair of 2's needs to find another 2). This number has to be switched with an adjacent number to create a row of 3 or more identical numbers.

To be valid, this number must not be touching either side (top and bottom for horizontal pairs, left and right sides for vertical pairs).

So, an example matrix:

```1, 4, 2, 3, 7, 3, 4, 5
2, 2, 5, 5, 7, 4, 7, 5
2, 4, 1, 2, 3, 6, 4, 6
5, 7, 6, 7, 7, 2, 7, 3
4, 6, 2, 4, 6, 7, 2, 1
6, 7, 2, 2, 6, 2, 6, 1
5, 5, 7, 1, 4, 6, 5, 7
5, 3, 4, 6, 6, 4, 7, 2```

Two Valid 7s:

```4, 1, 2, 3, 6
7, 6, 7, 7, 2
6, 2, 4, 6, 7```

Invalid 2:

```7, 6, 7
6, 2, 4
7, 2, 2
5, 7, 1```

Somebody up to the challenge? I'm still working on this myself, but I'm having a hell of a time with it.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...