Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

PROLOG PROGRAM TO FIND SUBLISTS OF THE GIVEN LIST

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

PROLOG PROGRAM TO FIND SUBLISTS OF THE GIVEN LIST.

Code for PROLOG PROGRAM TO FIND SUBLISTS OF THE GIVEN LIST in Artificial Intelligence

domains

    name = symbol
    namelist = name*
predicates
    sublist(namelist,namelist)
clauses
    sublist([],[]).
    
    sublist([First|Rest],[First|Sub]):-
        sublist(Rest,Sub).
        
    sublist([_|Rest],Sub):-
        sublist(Rest,Sub).


Output

Goal: sublist([a,x,y,b,c
d],[x,y])
Yes


Goal: sublist([a,x,y,b,c
d],[a,b])
Yes
Goal: sublist([a,x,y,b,c
d],[a,h])
No


Goal: sublist([a,b,c],X)
X=["a","b","c"]
X=["a","b"]
X=["a","c"]
X=["a"]
X=["b","c"]
X=["b"]
X=["c"]
X=[]
8 Solutions
  
Share: 


Didn't find what you were looking for? Find more on PROLOG PROGRAM TO FIND SUBLISTS OF THE GIVEN LIST Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of PROLOG PROGRAM TO FIND SUBLISTS OF THE GIVEN 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!