Lab 4 1. Discuss the solution to Assignment 1 ----------------------------- 2. List operations ------------------ 1. List Manipulation a. A predicate to compute the third element of a list (fails if the list has less elements). ?- third([a,b,c,d],X). X = c yes ?- third([a,b],X). No b. Remove the first occurrence of an element from a list ?- rm-dups(a, [a,b,a,c,c],L). L= [b,a,c,c] yes Remove all occurrences of an element from a list ?- rm-dups(a, [a,b,a,a,c,c],L). L= [b,c,c] yes c. Remove duplicate occurrences of an element rm-dups(L1,L2) -- L2 is the same as L1 with the second and succeeding immediately adjacent duplicates removed. For example: ?- rm-dups([a,b,a,a,a,c,c],[a,b,a,c]). Yes ?- rm-dups([a,b,a,a,a,c,c],X). X = [a, b, a, c] ; No ?- rm-dups([a,b,a,a,a,c,c],[a,b,c]). No d. Count element occurrences. count(L,E,N) holds if the list L contains E N times. Precondition: L and E are instantiated. L is a non-nested list. ?- count([1,2,1,1],1,3). Yes ?- count([1,2,1,1],1,N). N = 3 ; No ?- count([1,2,1,1],1,2). No ?- count([1,2,[1,2],1],[1,2],N). N = 1 ; No