Re: splitting lists





On 28 Нояб., 08:10, "Query Builder" <querybuil...@xxxxxxxxx> wrote:
I also have a question regarding matrix...

I have a 5 x 5 matrix.

A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y

this matrix is passed as a list (A, B, C,D,E,F G,H,I,
J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y).

I need to derive the following:
Row (M) should return ([A,B,C,D,E], [F,G,H,I,J], [K,L,M,N,O],
[P,Q,R,S,T], [U,V,W,X,Y])
Col(M) should return
([A,F,K,P,U],[B,G,L,Q,V],[C,H,M,R,W],[D,I,N,S,X],[E,J,O,T,Y])
Cross(M) should return([A,G,M,S,Y], [B,H,N,T,U], [C,I,O,P,V]....... so
on).

how do I get those functions?

I meeted the same problem during implementing Sudoku game and solved
that by specifying
row([A,B,C,D,E|_],1,[A,B,C,D,E]):-!.
row([_,_,_,_,_|T],N,R):- N>1, N1 is N-1, row(T,N1,R).

col([A,_,_,_,_,
B,_,_,_,_,
C,_,_,_,_,
D,_,_,_,_,
E|_],1,[A,B,C,D,E]):-!.
col([_|T],N,R):- N>1, N1 is N-1, col(T,N1,R).

.