Click here to Skip to main content
13,356,318 members (64,521 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Friends. How can I obtain the tracking of snakelike array within loops as shown in figure below?

Posted 15-Nov-12 3:57am
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?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100