Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to define two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length

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

Prolog program to define two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length.

Code for Prolog program to define two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    concatenate(l,l,l)
    evenlength(l)
    oddlength(l)
    
clauses
    concatenate([],L,L).
    
    concatenate([X|L1],L2,[X|L3]) :-
        concatenate(L1,L2,L3).
        
    evenlength([]).
    evenlength(L) :-
        concatenate(L1,[X1,X2|L2],L),
        evenlength(L2).
        
    oddlength([X]).
    oddlength(L) :-
        concatenate(L1,L2,L),
        oddlength(L1);
        oddlength(L2).

  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to define two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length 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].

 
No Comment Found, Be the First to post comment!