$30
AI Project #3: Prolog Challenges
Pick 6 of the 9 predicates and implement them in Prolog. Add code comments to show your
understanding and demonstrate with test cases.
REQUIREMENTS:
1. Find the last element of the list. last([a,b,c,d]),
2. Find the second last element of a list. nextlast([a,b,c,d]),
3. Find the K’th element of a list. kelement([a,b,c,d,e,f,g],5),
4. Find out whether a list is a palindrome. palin([a,c,c,b,a]), palin([a,b,c,c,b,a]),
5. Flatten a nested list structure. flatten([a,[b,[c,d],e]]),
6. Eliminate consecutive duplicates of list elements. compress([a,a,a,a,b,c,c,a,a,d,e,e,e,e,f]),
7. Drop every N’th element from a list. drop([a,b,c,d,e,f,g,h,i,k],3),
8. Remove the K’th element from a list. remove([a,b,c,d],3),
9. Insert an element at a given position into a list. insert(e,[a,b,c,d],3).
Submit a working .pl file that demonstrates the cases above with a significant number of code
comments to explain the operation of each predicate and also provide test cases.
Last Revised: January 21, 2018
1