To give some context, this problem is related to music theory.
I have a matrix I'm generating with this code:
row = {0, 5, 8, 1, 4, 9, 2, 7, 11, 3, 6, 10};
m = Table[row[[j]] - row[[i]], {i, 1, 12}, {j, 1, 12}];
m // MatrixForm
(Note row
can be any permutation of integers from 0 to 11 starting with 0.)
I want to find all the "chains" or "snakes" of numbers in the outputted matrix made by connecting adjacent numbers that differ by less than some delta. Basically, all the paths that exist on the matrix where each node differs by less than some number. Here is an example of some "chains" or "snakes" with delta <= 2 I found by hand in the matrix generated from row = {0, 5, 8, 1, 4, 9, 2, 7, 11, 3, 6, 10}
:
Obviously, you have the trivial "chain" or "snake" of zeroes of the diagonal, but then you have the rest of them. I don't know where to go from here. I don't know how to represent the matrix, and then what functions to use to find the "chains" or "snakes." If I can just output them as a list of lists, that would be fine.