In Prolog
1 Write a predicate oddList(List1,List2) which returns true if List2 contains the elements of List1 that occur in the odd-numbered positions (assuming 0-indexing).
Examples:
oddList([],[]) evaluates as true.
oddList([10],Y) unifies as Y = [].
oddList([1,2,3,4,5,6,7],[2,4,6]) evaluates as true.
oddList([8,3,1,6,9,12,15,21],X) unifies as X = [3,6,12,21].
2. Write a predicate evenList(List1,List2) which returns true if List2 contains the elements of List1 that occur in the even-numbered positions (assuming 0-indexing).
Examples:
evenList([],[]) evaluates as true.
evenList([10],Y) unifies as Y = [10].
evenList([1,2,3,4,5,6,7],[1,3,5,7]) evaluates as true.
evenList([8,3,1,6,9,12,15,21],X) unifies as X = [8,1,9,15].
3. Write a predicate mergeLists(List1,List2,List3) which returns true if List3 is List containing the elements of List1 in sequence followed by the elements of List2 insequence
Examples:
mergeLists([1,2,3],[4,5,6,7][1,2,3,4,5,6,7]) returns true.
mergeLists([1],[2],[1,2]) returns true.
mergeLists([1,2],[1,2],X) unifies as X = [1,2,1,2].
4. Write a predicate mergeSort(List1,List2) which returns true if List2 consists of the sorted elements of List1.
Examples:
mergeSort([8,5,7,3,9],[3,5,7,8,9]) returns true
5. There is a street with three neighboring houses that all have a different color, namely red, blue, and green. People of different nationalities live in the different houses and they all have a different pet. Here are some more facts about them:
-The Englishman lives in the red house.
-The jaguar is the pet of the Spanish family.
-The Japanese lives to the right of the snail keeper.
-The snail keeper lives to the left of the blue house.
Who keeps the zebra? Don’t work it out for yourself: define a predicate zebra/1 that tells you the nationality of the owner of the zebra!
(Hint: Think of a representation for the houses and the street. Code the four constraints in Prolog. You may find member/2 and sublist/2 useful.)
6. The formal language Even is very simple: it consists of all strings containing an even number of a’s, and nothing else. Note that the empty string ϵ belongs to Even. Write a program that generates Even .