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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started