Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program that defines a predicate maxlist (L,Max) where Max is the greatest number of the list

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

Prolog program that defines a predicate maxlist (L,Max) where Max is the greatest number of the list.

Code for Prolog program that defines a predicate maxlist (L,Max) where Max is the greatest number of the list in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    maxlist(l,x)
    max(x,x,x)
    
clauses
    max(X,Y,Max) :-
        X > Y,!,
        Max = X.
        
    max(X,Y,Max) :-
        Max = Y.
        
    maxlist([],0).
    maxlist([X],X).
    maxlist([X,Y|List],Max) :-
        max(X,Y,Max1),
        maxlist([Max1|List],Max).
        
Output :

Goal: maxlist([],M)
M=0
1 Solution

Goal: maxlist([-1,-2,-3,-4],M)
M=-1
1 Solution

Goal: maxlist([-8,-1,10,-2,-3,-4],M)
M=10
1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program that defines a predicate maxlist (L,Max) where Max is the greatest number of the list 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!