[solved] – Question 7457
1.Using Prolog as the programming language for LOGIC, construct the relevant command to do the following tasks:-
a.Prolog Lists – A list is either empty or it is composed of a first element (head) and a tail, which is a list itself. In Prolog we represent the empty list by the atom [] and a non-empty list by a term [H|T] where H denotes the head and T denotes the tail.
(NOTE:- Given list MySenarai= [a,b,c,d,e,f, g, h] for the tasks listed below)
i.Find the last element of a list.
?-
Output:-
ii.Find the K’th element of a list. (K=5)
?-
Output:-
iii.Eliminate consecutive duplicates of list elements.
?-
Output:-
iv.Find the number of elements of a list.
?-
Output:-
v.Reverse a list.
?-
Output:-
vi.Find out whether a list is a palindrome.
?-
Output:-
vii.Duplicate the elements of a list.
?-
Output:-
viii.Drop every N’th element from a list. (N=3)
?-
Output:-
ix.Insert an element at a given position into a list. (element = zzz)
?-
Output:-
x.Extract a slice from a list. (I = 2; k = 5)
Given two indices, I and K, the slice is the list containing the elements between the I’th and K’th element of the original list (both limits included). Start counting the elements with 1
?-
Output:-
Expert Answer
OR

