I must write a predicate to compute a row of Pascal's triangle. I try to write this with Binomial coefficient. In a first time, I managed to do it by displaying each result with writeln(). But I would like to save them in my list L. How can I do that ? Thank you
%coefficient(+N,+K,-R).
coefficient(_,0,1).
coefficient(N,N,1).
coefficient(N,K,R):-
N>=K,
K>0,
N1 is N-1,
K1 is K-1,
coefficient(N1,K,R1),
coefficient(N1,K1,R2),
R is R1+R2.
/* Get a line from the coeff binomial */
%line(+E,-L)
line(N,L):-
lineT(N,N,L).
lineT(_,0,_):-
writeln(1).
lineT(N,K,L):-
K > 0,
K1 is K-1,
coefficient(N,K,Zs),
writeln(Zs),
lineT(N,K1,[Zs|L]).
Result (condensed) : [debug] 124 ?- line(7,R). 1 7 21 35 35 21 7 1
Expected result (without writeln): [1,7,21,35,35,21,7,1]