Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program of predicate ordered (List) which is true if List is an ordered list of numbers

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

Define a predicate ordered (List) which is true
if List is an ordered list of numbers.
E.g. if the input is [1,5,6,6,9] then output is yes
and if input is [9,4,5] the output is no.

Code for Prolog program of predicate ordered (List) which is true if List is an ordered list of numbers in Artificial Intelligence

domains

    list=integer*

    
predicates

    order(list)

    
clauses
    
    order([X]).
    
    order([X,Y|Tail]):-
        X<=Y,
        order([Y|Tail]).

            
OUT PUT
=======

Goal: order([1,2,3,4])

Yes

--------------------------

Goal: order([1,2,5,3])

No

--------------------------

Goal: order([1,5,6,6,9])

Yes

--------------------------

Goal: order([9,4,5])

No
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program of predicate ordered (List) which is true if List is an ordered list of numbers 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!