# Identifing an isolated character in a matrix

• (2 Pages)
• 1
• 2

## 17 Replies - 2734 Views - Last Post: 18 December 2012 - 07:03 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=303739&amp;s=074dd6f92e20466c931ca61e4b0560a1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #16 CTphpnwb

• D.I.C Lover

Reputation: 3389
• Posts: 12,002
• Joined: 08-August 08

## Re: Identifing an isolated character in a matrix

Posted 18 December 2012 - 06:46 AM

Aside from your current attempt I think you need to determine what is meant by adjacent. In a two dimensional array an element can be seen to have as many as 8 adjacent values: above left, above, above right, left, right, below left, below, and below right. You're only considering the two values in the same row.

### #17 domenico

Reputation: 0
• Posts: 90
• Joined: 21-July 12

## Re: Identifing an isolated character in a matrix

Posted 18 December 2012 - 06:49 AM

I'm considering the same situation described by you.
Doesn't the code work with that?

### #18 CTphpnwb

• D.I.C Lover

Reputation: 3389
• Posts: 12,002
• Joined: 08-August 08

## Re: Identifing an isolated character in a matrix

Posted 18 December 2012 - 07:03 AM

So you are! Sorry, I misread a post or two.

```Enter the number of rows of the matrix associated to the bitmap: 4
Enter the number of columns of the matrix associated to the bitmap:  4
Enter the element [0][0]: 1
Enter the element [0][1]: 0
Enter the element [0][2]: 0
Enter the element [0][3]: 0
Enter the element [1][0]: 0
Enter the element [1][1]: 1
Enter the element [1][2]: 0
Enter the element [1][3]: 0
Enter the element [2][0]: 0
Enter the element [2][1]: 0
Enter the element [2][2]: 0
Enter the element [2][3]: 0
Enter the element [3][0]: 0
Enter the element [3][1]: 0
Enter the element [3][2]: 0
Enter the element [3][3]: 0

1 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0

The bitmap does not contain an isolated point.

```

So it appears to be working, but you need to test more.

I'd have the matrix read in from a file. That way you could change file names for different tests, allowing you to check situations with 1s in corners, sides, and the middle.