Search:

# Artificial Intelligence Articles

Submit Article
 RSS Feeds

# Prolog program to define the relation shift(List1, List2) so that List1 shifts rotationally by one element to the right

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 5650

## Code for Prolog program to define the relation shift(List1, List2) so that List1 shifts rotationally by one element to the right in Artificial Intelligence

```domains

list=integer*

predicates

shift(list,list)
del(list,list,integer)
add(list,integer,list)

clauses

shift(L1,L2):-
del(L1,L3,X),
add(L3,X,L2).

del([X],[],X).

del([Head|Tail],[Head|L],X):-
del(Tail,L,X).

add(L3,X,[X|L3]).

OUT PUT
=======

Goal: shift([1,2,3,4,5],List)

List=[5,1,2,3,4]

1 Solution

-------------------------------------

Goal: shift([1,2,3,4,5,6,7,8,9],List)

List=[9,1,2,3,4,5,6,7,8]

1 Solution
```
Share:

 Milind Mishra author of Prolog program to define the relation shift(List1, List2) so that List1 shifts rotationally by one element to the right is from India. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!