Question: /* Problem 4: Write a predicate is_decreasing(X) that succeeds if X is a list of decreasing numbers -- Each number is either the same or

/* Problem 4: Write a predicate is_decreasing(X) that succeeds if X is a list of decreasing numbers -- Each number is either the same or lower than the preceding number.

NOTE: You may match two elements at a time against a list: [X,Y|Xs] = List. It's preferable to do it in the rule head however... some_rule([X,Y|Xs]) :- ... */

/* Problem 5 Test: */ %:- is_decreasing([]). % SUCCEED %:- is_decreasing([10]). % SUCCEED %:- is_decreasing([10,9]). % SUCCEED %:- is_decreasing([10,9,7]). % SUCCEED %:- is_decreasing([10,9,7,7,2]). % SUCCEED %:- is_decreasing([1,1,1,1,1]). % SUCCEED

%:- is_decreasing([10,9,7,9]) -> fail ; true. % FAIL %:- is_decreasing([2,3,1]) -> fail ; true. % FAIL %:- is_decreasing([1,2,3]) -> fail ; true. % FAIL %:- is_decreasing([7,19])-> fail ; true. % FAIL

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!