Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to define a relation dividelist (L,L1,L2) so that L is partitioned into L1 and L2 where length of L1 and L2 are almost same

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

Prolog program to define a relation dividelist (L,L1,L2) so that L is partitioned into L1 and L2 where length of L1 and L2 are almost same.

Code for Prolog program to define a relation dividelist (L,L1,L2) so that L is partitioned into L1 and L2 where length of L1 and L2 are almost same in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    dividelist(l,l,l)
    
clauses
    dividelist([],[],[]).
    
    dividelist([X],[X],[]).
    
    dividelist([X1,X2|List],[X1|List1],[X2|List2]) :-
        dividelist(List,List1,List2).
        

Output :

Goal: dividelist([1,2,3,4,5,6,7,8],List1,List2)

List1=[1,3,5,7], List2=[2,4,6,8]
1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to define a relation dividelist (L,L1,L2) so that L is partitioned into L1 and L2 where length of L1 and L2 are almost same is from India.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Artificial Intelligence:


 
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!