This problem seems like it may be related to a multi-value version of "Gray codes": see http://en.wikipedia.org/wiki/Gray_code for general information and http://www.jsoftware.com/jwiki/Essays/Gray%20Code and http://www.jsoftware.com/jwiki/RE%20Boss/Performance%20Records/Gray%20codefor J implementations.
Briefly, a Gray code is an alternate way of counting in binary with the objective of minimizing the number of bit changes between successive entries, e.g. 0 0 0 0 0 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 is the 3-bit sequence: there's only a single-bit difference between any adjacent pair (and, cyclically, between the first and last one). ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
