I wanna build a predicate that given a List
of lists and a Element
with coordinates X, checks if X belong to any list inside that main List, and if it belongs to any list, returns the ReturnList
as a list with elements up until the position of where the Element X is found.
So for example, given;
?-checklist((3,4),[[(1,3), (1,2), (1,1)],[(1,4), (2,4), (3,4), (4,4)]], ReturnList)
returns
ReturnList = [(1,4), (2,4), (3,4)]
I'm trying to implement this and so far I have
get_list([],_,[]).
get_list([List], Element, ReturnList):-
member(List, Element),
get_list(List|Rest, Element, List).
But It's one of my first prolog programs and I'm finding it difficult to grasp the logic