Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help me

Status
Not open for further replies.

munni11

Programmer
Jul 16, 2008
1
0
0
subsequence (list1,list2) is satisfied if the elements of list1 occur in the same order in list 2 . That means that whenevr x precedes y in list 1 x occurs before y in list2. fro example subsequence ([a,b,c],[1,a,2,3,b,4,5,c,6]) is satisfied becuase in the second list a occurs before b and b occurs before c. The first list may have duplications, so
subsequence ([a,b,a,c],[a,1,c,2,a,b,3,4,b,4,c,5,6,a,7,c])is satisfied because the first a the first b the third a and the third a have same order in second list as in the first.
COuld you please guide me on how to test these goals
1)subsequence ([a,b,c],[1,2,3,c,a,4,5,b])
2)subsequence ([a,b,a],[b,1,2,a,4,5,a])
 
try this:

subsequence([A|B], [C|D]) :-
A = C,
!,
subsequence(B,D).

subsequence([A|B], [C|D]) :-
A \= C,
!,
subsequence([A|B], D).
subsequence([],_) :-!.
subsequence(A,[]) :-
!,
fail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top