How to transpose a matrix in prolog
问题 How can I transpose a list like [[1,2,3][4,5,6][6,7,8]] to [[1,4,6],[2,7,8],[3,6,9]] ? To depict it: I'd like to flip the matrix 90 degree to the left. How can I do that? 回答1: Not sure your example is correct, but I get the idea. If using SWI-PROLOG, you can use the CLPFD module, like so: :- use_module(library(clpfd)). Allowing you to use the transpose/2 predicate, like this: 1 ?- transpose([[1,2,3],[4,5,6],[6,7,8]], X). X = [[1, 4, 6], [2, 5, 7], [3, 6, 8]]. Otherwise (if no SWI-PROLOG), you