I want to find if a given element exists in a list of lists. I am only getting true if the element exists somewhere is the first list of lists.
Any advice?
memberlist(X,[[X|T1]|T2]).
memberlist(X,[[H|T1]|T2]) :-
memberlist(X,[T1|T2]).
I want to find if a given element exists in a list of lists. I am only getting true if the element exists somewhere is the first list of lists.
Any advice?
memberlist(X,[[X|T1]|T2]).
memberlist(X,[[H|T1]|T2]) :-
memberlist(X,[T1|T2]).
Here is my approach using
sort/2
andflat/2
that flatten a list only one level:Testcases: