Homework 3. ============== 1. Write a predicate that accepts a list and succeeds if that list has exactly three elements. ============= 2. Write a predicate that accepts a list and generates from it a similar list with the first two elements swapped. It should work like this: ?-swap_first_two([a,b,c,d], [b,a,c,d]). Yes ?-swap_first_two([a,b,c,d], X). X= [b,a,c,d]; No ?-swap_first_two(X, [b,a,c,d]). X=[a,b,c,d]; No ?-swap_first_two([a,b,c,d], [b,a,d,c]). No ?-swap_first_two([a,b,c,d], [X,Y,c,d]). X=b Y=a; No ================================= 3. Define the relation reverse_list(List, Reversed_List) that reverses lists, e.g.: ?- reverse_list([a,b,c,d],[d,c,b,a]). yes ?- reverse_list([a,b,c,d],X). X=[d,c,b,a]; No ================================= 4. Define the predicate palindrome(List) that recognizes palindromes. A list is a palindrome if it reads the same in the forward and in the backward direction. For example: ?- palindrome([m,a,d,a,m]). yes ?- palindrome([s,i,r]). No ================================= 5. Define the relation shift(List1, List2) so that List2 is List1 "shifted rotationally" by one element to the left. For example, ?- shift([1,2,3,4,5], L1), shift(L1,L2). L1=[2,3,4,5,1] L2=[3,4,5,1,2]; No ================================ 6. Define the relation maximum(List,Integer) that succeeds if Integer is the maximal element of the list of integers List. Example, ?- maximum([1,2,3,4,2,-1,4],Max). Max=4; No ?- maximum([],Max). No