Below is your prolog predicate. Let me know if you have any issue in comments.
% remove_consecutive_duplicates(L1,L2) :- the list L2 is
obtained from the list L1 by
% removing repeated occurrences of elements into a single
copy
% of the element.
% (list,list) (+,?)
remove_consecutive_duplicates([],[]).
remove_consecutive_duplicates([X],[X]).
remove_consecutive_duplicates([X,X|Xs],Zs) :-
remove_consecutive_duplicates([X|Xs],Zs).
remove_consecutive_duplicates([X,Y|Ys],[X|Zs]) :- X \= Y,
remove_consecutive_duplicates([Y|Ys],Zs).
Sample Run: -

Prolog questions. Thanks! Write a predicate that removes consecutive duplicate elements from a list. ?- remove_consecutive_duplicates...
Code in prolog a predicate windows/3 that returns the list of all windows (sublists of consecutive elements) of length 3 of the given list. ?- windows([1,3,a,4,b],Ys). Ys = [[1,3,a],[3,a,4],[a,4,b]] ?- windows([1,3],Ys). Ys = []
Code in Prolog a predicate swapFirstTwo/2 that swaps the rst two elements of the given list. If the list is too short, it must fail. ?- swapFirstTwo([a,b,c,d,e], Ys). Ys = [b,a,c,d,e]. ?- swapFirstTwo([a], Ys). false.
Question 3 (13] (a) Write a procedure filter (L,PredName, L1,L2) that accepts a list L and returns two lists Li and L2, where Li contains all elements in L for which PredName (x) fails, and L2 contains all elements in L for which PredName (x) succeeds. The predicate PredName/1 should be defined when calling the procedure filter. For example: let test be defined as test(N).- N > 0. 7- filter((-6,7,-1,0),test,L1,L2). L1 - (-6.-1) L2 - [7, 0] NB Use the...
SWI-Prolog a) Write a predicate called lastEle(Atom,List) to find the last element of a list. You may not use the built-in last predicate in your answer. E.g., ?- lastEle(X,[how,are,you,today]). X=today. b) Write a predicate gradeMap(L,R), where L is a list of percentage grade values (integers from 0 to 100), and R is a list of corresponding grade letters (a-f, no +/-'s). You may assume the grade list contains the correct types. E.g., ?-gradeMap([0, 16, 49, 55, 63, 78, 92], R)....
PROLOG: Write a prolog predicate that counts occurrences of 'x', 'y', or 'z' in a list. For example, count([x,[y,[a,2],[a,3]],[a,4]], 2) should return true. I only want to count occurrences of x,y,z not a. the base case is that any [a,int] list will have a count of 0. So any sublist with 'a' does not count. another example of what will return true is: count([x,[a,1],[a,5]], 1) The predicate must have the form count(X,Y) where X is the list structure passed and...
In Prolog language, write a recursive predicate to find the last element of a list. You may not use the built-in last predicate in your answer. E.g., ?- lastEle(X,[how,are,you,today]). X=today.
In PROLOG, write a binary predicate fof, short for 'full of full', which will precede each atom in a list by the atom full. E.g. ?- fof([a,b,c]),L). L = [full,a,full,b,full,c] NOTE: only atoms, not numbers or lists or trees.
(Remove duplicates) Write a method that removes the duplicate elements from an array list of integers using the following header: public static void removeDuplicate(ArrayList < Integer > list) Write a test program that prompts the user to enter 10 integers to a list and displays the distinct integers in their input order separated by exactly one space. Sample Run 1 Enter ten integers: 34 5 3 5 6 4 33 2 2 4 The distinct integers are 34 5 3...
# PrologWrite a predicate that returns the second to last element in a list. ?- second last clement(x, [a.b.c.d,e] x = d?- second last element (X, []) false. ?- second last element (3, [5,4,3,2,1])true.
Write a program in prolog to reverse the elements of a list. Don't call the following library functions that already exist. reverse_list([], []). reverse_list([Head | Tail], Out) :- reverse_list(Tail, TailReversed), append(TailReversed, [Head], Out).