/** ?- eat_chocolate(2,A,B). A = [lift, bite, chew, swallow], B = [2, 1] ; ** eat_chocolate(N,[lift,bite,chew,swallow],List) :- bites(N, [], List). bites(0,List,List) :-!. bites(N,List1,List3) :- N1 is N-1, append(List1,[N],List2), bites(N1,List2,List3). Suppose he takes 2 bites to finish the dried apricot. Write 2 down. All right. What is 2-1? 1 Will he repeat this when there is 1 bite left, and so on until there are no bites left? **/ %% ?- find_links([[hand,1,2],[mouth,2,3],[food-pipe,3,4],[stomach,4,5]],1,5,List). %% List = [hand, mouth, food-pipe, stomach] %% find_links(Links,First,Last,List) %% Links - List of [Item,Position1,Position2] %% Item - e.g. hand, which moves between %% positions 1 (Position1) and 2 (Position2) %% First - first position %% Last - last position %% List - the list of positions in order find_links(Links,First,Last,List) :- find_links(Links,First,Last,[],List). %% find_links(Links,First,Last,List1,List) %% Links, First, Last, List are the same as for find_links/4 %% List1 - the current list of positions find_links(_,Last,Last,List,List). find_links(Links1,Curr,Last,List1,List2) :- delete(Links1,[Item,Curr,Next],Links2), append(List1,[Item],List3), find_links(Links2,Next,Last,List3,List2).