How to construct a list in Prolog? -
let's want construct list 10 elements each elements can 0 or 1 or 2. have 2 lists list1 , list2, positions of 1 , 2. how can construct whole list using function this:
construct(list1,list2,l). example:
input:
construct([1,3,5],[8],l) output:
l = [1,0,1,0,1,0,0,2,0,0]
what
constructh(top, top, _, _, []). constructh(num, top, l1, l2, [1 | ho]) :- num < top, member(num, l1), np1 num+1, constructh(np1, top, l1, l2, ho). constructh(num, top, l1, l2, [2 | ho]) :- num < top, member(num, l2), np1 num+1, constructh(np1, top, l1, l2, ho). constructh(num, top, l1, l2, [0 | ho]) :- num < top, \+ member(num, l1), \+ member(num, l2), np1 num+1, constructh(np1, top, l1, l2, ho). construct(list1, list2, lout) :- constructh(1, 11, list1, list2, lout). ?
Comments
Post a Comment