Identifing an isolated character in a matrix

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1467 Views - Last Post: 18 December 2012 - 07:03 AM Rate Topic: -----

#16 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2881
  • View blog
  • Posts: 9,953
  • 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.
Was This Post Helpful? 0
  • +
  • -

#17 domenico  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • 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?
Was This Post Helpful? 0
  • +
  • -

#18 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2881
  • View blog
  • Posts: 9,953
  • 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.

When I ran your latest version I got this:
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.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2