Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to reverse a list using concatenate

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

Prolog program to reverse a list using concatenate.

Code for Prolog program to reverse a list using concatenate in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    reverse(l,l)
    concatenate(l,l,l)
    
clauses
    concatenate([],List,List).
    
    concatenate([X|List1],List2,[X|List3]) :-
        concatenate(List1,List2,List3).
        
    reverse([],[]).
    
    reverse([Head|Tail],List) :-
        reverse(Tail,List1),
        concatenate(List1,[Head],List).
        
Output :

Goal: reverse([2,1,3,4],List)
List=[4,3,1,2]
1 Solution
  
Share: 


Didn't find what you were looking for? Find more on Prolog program to reverse a list using concatenate Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program to reverse a list using concatenate 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!