I'd like to write a function that determines all the diagonal elements in a matrix are same.
For instance:
?-diagonal([[1,2,3,4],
[2,1,5,6],
[6,2,1,9],
[8,7,5,1]]).
true.
Any help is appreciated.
I'd like to write a function that determines all the diagonal elements in a matrix are same.
For instance:
?-diagonal([[1,2,3,4],
[2,1,5,6],
[6,2,1,9],
[8,7,5,1]]).
true.
Any help is appreciated.
Question solved...
diagonal([],_,_).
diagonal([Head|Tail],Index,Value),
nth0(Index,Head,Value),
IndexNext is Index+1,
diagonal(tail,IndexNext,Value).
Test:
?- diagonal([[1,2,3],
[5,1,6],
[9,3,1]],0,X).
X=1.