Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

PROLOG PROGRAM TO SPLIT A LIST IN TWO LISTS SUCH THAT ONE LIST CONTAINS NEGATIVE NUMBERS AND ONE CONTAINS POSITIVE NUMBERS

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

PROLOG PROGRAM TO SPLIT A LIST IN TWO LISTS SUCH THAT ONE LIST CONTAINS NEGATIVE NUMBERS AND ONE CONTAINS POSITIVE NUMBERS.

Code for PROLOG PROGRAM TO SPLIT A LIST IN TWO LISTS SUCH THAT ONE LIST CONTAINS NEGATIVE NUMBERS AND ONE CONTAINS POSITIVE NUMBERS in Artificial Intelligence

domains
    list=integer*

predicates
    split(list,list,list)
clauses
    split([],[],[]).
    split([X|L],[X|L1],L2):-
        X>= 0,
        !,    
        split(L,L1,L2).
        
    split([X|L],L1,[X|L2]):-
        split(L,L1,L2).

Output :        

Goal: split([1,2,-3,4,-5
,2],X,Y)
X=[1,2,4,2], Y=[-3,-5]
1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of PROLOG PROGRAM TO SPLIT A LIST IN TWO LISTS SUCH THAT ONE LIST CONTAINS NEGATIVE NUMBERS AND ONE CONTAINS POSITIVE NUMBERS 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].

 
Anuj Kalra from India Comment on: Apr 21
awesome program
modified it to separate even numbers
worked like a charm

but i'm new to prolog and do not understand how the code works!

could you please explain??
pretty pleeeaaaaaseee??????

View All Comments