Can someone help me with the Sublist Predicate (Prolog)? -
i want implement predicate sublist1(i1,i2,l,sub) takes list l , returns sub includes elements of l index i1 index i2. code gives me false time . idea what's wrong?
sublist1(0,0,[h|t],[h|sub]). sublist1(i1,i2,[h|t],sub):- i1 =0, i2>=i1, i2-1, sublist1(i1,i,t,[h|sub]). sublist1(i1,i2,[h|t],_):- i1>0, i2>i1, ii1 i1-1, ii2 i2-1, sublist1(ii1,ii2,t,_).
algorithmically, should work :
% sublist 0 0 should return [h] list sublist1(0,0,[h|t],[h]). % sublist 0 n should return first element followed sublist 0 n-1 of tail sublist1(i1,i2,[h|t],[h|sub]):- i1 0, i2 > 0, ii2 i2 - 1, sublist1(i1,ii2,t,sub). % sublist of [h|t] i1 i2 should return sublist i1-1 i2-1 of t sublist1(i1,i2,[h|t],sub):- i1>0, i2>i1, ii1 i1-1, ii2 i2-1, sublist1(ii1,ii2,t,sub).
edit
try online (run execute , write sublist1(2,5,[0,1,2,3,4,5,6,7,8],s).
example). use alt+91
[
, alt+93
]
Comments
Post a Comment