Re: splitting lists
- From: "ony" <virkony@xxxxxxxxx>
- Date: 6 Dec 2006 06:18:43 -0800
On 28 Нояб., 08:10, "Query Builder" <querybuil...@xxxxxxxxx> wrote:
I also have a question regarding matrix...I meeted the same problem during implementing Sudoku game and solved
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?
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).
.
- Prev by Date: Re: Generate all 384 diabolic square
- Next by Date: Re: Arithmetic puzzle
- Previous by thread: Re: splitting lists
- Next by thread: Re: odbc or other database-like interface TO Prolog
- Index(es):