Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to generate the sublist of a given list

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

Prolog program to generate the sublist of a given list.

Code for Prolog program to generate the sublist of a given list in Artificial Intelligence

trace
domains
    x = integer
    l = integer*
    
predicates
    concatenate(l,l,l)
    sublist(l,l)
    
clauses
    concatenate([],List,List).
    
    concatenate([X|List1],List2,[X|List3]) :-
        concatenate(List1,List2,List3).
        
    sublist(SubList,List) :-
        concatenate(List1,SubList,List3),
        concatenate(List3,List2,List),
        write(SubList," is a sublist of ",List),nl.
        
    sublist(SubList,List) :-
        write(SubList," is not a sublist of ",List),nl.
        
Output :

Goal: sublist([2,3,4],[1,2,3,4,5])

[2,3,4] is a sublist of
[1,2,3,4,5]
Yes
  
Share: 


Didn't find what you were looking for? Find more on Prolog program to generate the sublist of a given list Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program to generate the sublist of a given list is from India.
 
View All Articles

 

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!