Q 10. Write a prolog procedure every-other/2 that receives a source list as its first argu- ment and produces a list in
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Q 10. Write a prolog procedure every-other/2 that receives a source list as its first argu- ment and produces a list in
Q 10. Write a prolog procedure every-other/2 that receives a source list as its first argu- ment and produces a list in the second argument whose elements are the elements of odd indexes in the source list. Examples are given in the following: ?- every-other ([], L) L = []. ?- every-other ([1], L) L = [1]. ?- every-other ([1, 2], L) L = [1]. ?- every-other ([1, 2, 3], L) L = [1, 3]. ?- every-other ([1, 2, 3, 4], L) L = [1, 3]. Make sure your procedure is efficiently terminated.