12,063,909 members (64,926 online)
Rate this:
See more:
Hello Friends. How can I obtain the tracking of snakelike array within loops as shown in figure below?

[IMG]http://i49.tinypic.com/2ev3o94.png[/IMG]
Posted 15-Nov-12 3:57am
BerkanH299

First of all, as this picture does not show one continues path through the array, it's not quite clear what is required. This is rather a description of some partial order. So, not clear what you want to achieve. To perform some operation on the array in certain order? But, due to having a partially ordered set, there is more than one possible path. So, what exactly you want to achieve? Do always you need to work with an array 6x8? How about other cases?
--SA

Rate this:

## Solution 1

Please see my comment to the question.

Here is the idea: showing the picture does not mean definition of the problem. Moreover, showing one particular example is also not a definition of the problem. By an example, it's usually possible to find some different algorithms doing different things is some general case which is not formally described.

The code is pretty much like a statement in mathematics: it does not just express some idea, more or less vague. It always defines something in an absolutely certain way, even when this absolute level of certainty is not required by some practical purpose. Every such definition or algorithm hold the notion of infinity in its depth: it defines some invariant behavior, which does not depend on how and when the code was compiled, how many times executed (it it is stateless, of course), on what what CPU, at what time, etc. It always define some invariant behavior, without any ambiguity. So, the requirements to the algorithm should meet this level or certainty.

That said, this is one of the typical cases, when the solution of the problem is nearly equivalent to its strict formulation. Here is what you have to do: formulate the problem in the form of text fully understandable to all qualified readers, in a fully unambiguous way. You will see that it would require strict mathematical language. As soon as you do it, you will see that the algorithm is already there — you only need to translate it from you declarative language to some imperative language. Such as Java.

There are very many cases, when such translation itself is extremely difficult; and there is a good number of unsolved problems, well known in the world. But not in your case. I'm pretty sure in your simple case this is all what involved, there is nothing else.

Consider I gave you a universal algorithm for solving of unlimited number of similar problems: formulate it strictly, and immediately see the solution.

—SA
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 CPallini 205 d@nish 200 CHill60 160 ppolymorphe 89 Chris Maunder 80
 Dave Kreskowiak 1,827 Richard MacCutchan 1,250 d@nish 980 OriginalGriff 844 CPallini 740

Advertise | Privacy | Mobile
Web02 | 2.8.160204.4 | Last Updated 15 Nov 2012