Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Program that defines a relation split(L,P,N) where list is divided into positive, negative numbers without using cut

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

Program that defines a relation split(L,P,N)
where List - a list of numbers is divided into
Positive - a list of positive numbers and
Negative - a list of negative numbers
without using cut.

Code for Program that defines a relation split(L,P,N) where list is divided into positive, negative numbers without using cut in Artificial Intelligence

domains
    l = integer*
    
predicates
    split(l,l,l)
    
clauses
    split([],[],[]).
    
    split([X|List] , Positive , [X|Negative]) :-
        X < 0,
        split(List,Positive,Negative).
        
    split([X|List] , [X|Positive] , Negative) :-
        X >= 0,
        split(List,Positive,Negative). 

        
Output : 

Goal: split([-1,1,-2,2,-3,3],PosList,NegList)
PosList=[1,2,3], NegList=[-1,-2,-3]
1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of Program that defines a relation split(L,P,N) where list is divided into positive, negative numbers without using cut 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!