How to multiply all elements of two lists with each other in Prolog

后端 未结 5 1121
终归单人心
终归单人心 2021-01-22 00:12

I am thinking how to multiply all elements of two list with each other. Then I want to put all results in List3. For example,

List1 = [1,3,5].
List         


        
5条回答
  •  有刺的猬
    2021-01-22 00:44

    Why not

    prod(L1, L2, LP) :-
        bagof(P, X^Y^(member(X, L1), member(Y, L2), P is X * Y), LP).
    

提交回复
热议问题