Ok I have found the problem!
I dont know why its like that, but when I tried duplicating the function setof() into my file and renamed it to setof2() like this:
longest(List,SubList) :- setof2([Len,DecrSub],decreasing_sublist(List,Len,DecrSub),Ye),reverse(Ye,Y),funky(Y,SubList)...
I thought of that but it isnt the case, i even changed the predicate name and it did the same thing.
I tried this predicate:
longest22(List,Ye) :- setof([Len,DecrSub],decreasing_sublist(List,Len,DecrSub),Ye).
and this in the command line:
18 ?- longest22([5,7,4,9,3,2,1],SubList).
and i got...
hey kahleen,
Ive tried tracing Ive tried every predicate individually. It all looks fine, also each predicate individually returns the result only once. Its only when they are encapsulated by my function it gives duplicates. I also noticed that when I use your funky, and I put an exclamation...
First off, thanks for the gui tracer, I didnt know it existed and it certainly helps me alot.
I used it, and it worked fine.
The duplicate I get is when i do the ";" symbol after my first result.
I tried to trace why it backtracks and does it all over and couldnt understand why.
I do think it...
Hey kahleen,
I still get this:
4 ?- longest([5, 7, 4, 9, 3, 2, 1], Seq).
Seq = [[7, 4, 3, 2, 1], [5, 4, 3, 2, 1]] ;
Seq = [[7, 4, 3, 2, 1], [5, 4, 3, 2, 1]].
I use SWI-Prolog as instructed in our course.
Furthermore, the professor insisted we dont use the ! symbol as to his opinion just covers...
thanks so much for your reply.
I understand my lack of efficiency on the first line of funky.
But I do want all decreasing subsets. If I remove my second line of funky all i get is one long subsequence and not all the longest ones.
Still, with the new funky, I do get duplicates even for one...
Hi everyone,
Im trying to code the Longest Decreasing Subsequences out of a given List in prolog.
The problem is is that i get duplicates of the answers.
here is my code:
sublist([],[]).
sublist([X|R],[X|S]):- sublist(R,S).
sublist([_|R],S):- sublist(R,S).
% longest(List,SubList)/2 with mode...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.