> the only thing I need is > to find and count such numbers in an array (it's a matrix) > that don't > have bigger or the same number in their surroundings, such > as this: > > 1 2 3 > 7 8 5 > 4 2 1
Think carefully about what you mean by "in their surroundings". For example, do diagonally adjacent numbers count as neighbours, or only vertically and horizontally adjacent numbers? Is the geometry toroidal, i.e. is the top edge identified with the bottom edge and the left with the right, as in some video games? Are we talking about next-door neighbours, or do next-door-but-one neighbours also count? The situation seems to contain symmetries. You can simplify things considerably if you make maximum use of this fact. (This idea is commonly used in noughts-and-crosses/tic-tac-toe programs.) Try and write a mathematical expression (a set) defining the neighbours of the ij-th cell. (Sometimes it's easier to define non-neighbours than neighbours. The two sets are complementary.) Once you've done this, the algorithm you need should become obvious. David
