Search:

# Artificial Intelligence Articles

Submit Article
 RSS 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: 17857

## 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 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

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!