Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog list problem

[a,b,c,d] and
[[1,2,3,4],[5,6,7,8],[43,34,56,5],[23,32,2,2]]

I want to make

[[a,1,2,3,4],[b,5,6,7,8],[c,43,34,56,5],[d,23,32,2,2]]

I use swi prolog is it possible do it ?

Thanks a lot.

like image 852
selda Avatar asked Sep 06 '26 11:09

selda


1 Answers

solve([], [], []).

solve([[X|Y]|S], [X|L1], [Y|L2]):-
  solve(S, L1, L2).

UPDATE: How to use

Write the function in a file "a.pl", then in swi-prolog type:

['a.pl'].

then type:

solve(X, [a,b,c,d], [[1,2,3,4],[5,6,7,8],[43,34,56,5],[23,32,2,2]]).

You will get:

X = [[a, 1, 2, 3, 4], [b, 5, 6, 7, 8], [c, 43, 34, 56, 5], [d, 23, 32, 2, 2]] 

I have the strange feeling that I am doing your homework. Is it?

like image 193
Vincent Cantin Avatar answered Sep 09 '26 23:09

Vincent Cantin