I’m trying to generate all possible ‘ways’ from one element in matrix to another, Main conditional says that Element in matrix can be connected with other only if elements share at least one corner so in that matrix
[[1,2,3]
[5,4,6]
[8,9,7]]
1 can be only conected with 2,4,5 but 4 is conected with all elements. Is it possible to represent that list as graph without using attract? Or maybe I can find out any easier way to do it
Thanks for all answers.
Ok i set forth 🙂
Now with predicates I generated all ‘edges’ but i cannot use them anywhere, I could not figure out, how to add to accumulator(list) infomrations of each cell with such pattern ([row:R1,column:C1,value:V1], [row:R2,column:C2,value:V2]).
Enumeration of a finite set can be done easily using Prolog backtracking:
Using paired nth1/3 we can access a cell:
So, in a matrix NxM of distinct elements:
simple test:
yields:
Note that the test
R > 1andC > 1could be avoided, demanding to nth1/3 failure the ‘out of band’ test. The same is true for the upper limit, omitted indeed, with the added benefit that we are not limited to a predefined matrix size.