Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to find the permutations of a given list i.e. to find all possible combinations of the elements of a list

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

Prolog program to find the permutations of a given list i.e. to find all possible combinations of the elements of a list.

Code for Prolog program to find the permutations of a given list i.e. to find all possible combinations of the elements of a list in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    concatenate(l,l,l)
    delete(x,l,l)
    insert(x,l,l)
    permutation(l,l)
    
clauses
    concatenate([],L,L).
    
    concatenate([X|L1],L2,[X|L3]) :-
        concatenate(L1,L2,L3).
        
    delete(X,L,L1) :-
        concatenate(L3,[X|L2],L),
        concatenate(L3,L2,L1).
        
    insert(X,L1,L) :-
        delete(X,L,L1).
        
    permutation([X],[X]).
    
    permutation([X|T],L) :-
        permutation(T,T1),
        insert(X,T1,L).
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to find the permutations of a given list i.e. to find all possible combinations of the elements of a list is from India.
 
View All Articles

 
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!