Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

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

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

Prolog program to define the relation shift(List1, List2) so that List1 shifts rotationally by one element to the left. E.g. if the input is shift([1,2,3,4,5], L) then
the output should be [2,3,4,5,1].

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

domains

    list=integer*

    
predicates

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

    
clauses

    shift(L1,L2):-
        del(L1,L3),
        add(L3,L1,L2).
        
    del([Head|Tail],Tail).
    
    add([],[Head|Tail],[Head]).
    
    add([Head|Tail],L1,[Head|L2]):-
        add(Tail,L1,L2).


OUT PUT
=======

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

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

1 Solution

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

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

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

1 Solution
  
Share: 



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

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!