%% Connect strands of reasoning on an internet page together for the reader, as two notes converge %% Finds all the strands of instructions which connect to a certain point, and connects them to it, and prints the graph in a depth first manner. %% print(a,[[a,b],[c,d],[b,c]],Graph). %% Graph = [[a, b], [b, c], [c, d]] ; print(FirstItem,Items1,Graph) :- find_items(FirstItem,Items1,_Items2,[],Graph). find_items(Item1,Items,Items,Graph,Graph) :- not(member(Pair,Items)), Pair = [Item1,_Item2]. find_items(Item1,Items1,Items2,Graph1,Graph2) :- member(Pair,Items1), delete(Items1,Pair,Items3), Pair = [Item1,Item2], append(Graph1,[Pair],Graph3), find_items(Item2,Items3,Items2,Graph3,Graph2). %% Finds duplicated content on the Internet %% eliminate_duplicates([a,a,a,b,b,c],[],List). %% List = [a, b, c] ; eliminate_duplicates([],List,List). eliminate_duplicates([Item|Items1],List1,List2) :- delete1(Items1,Item,[],Items2), append(List1,[Item],List3), eliminate_duplicates(Items2,List3,List2). delete1([],_,Items,Items). delete1([Item|Items1],Item,Items2,Items3) :- delete1(Items1,Item,Items2,Items3), !. delete1([Item2|Items1],Item1,Items2,Items3) :- append(Items2,[Item2],Items4), delete1(Items1,Item1,Items4,Items3).