1.4 Sorted Lists Write a predicate sorted(Xs) that determines if a list of numbers Xs is…
- User
1.4 Sorted Lists Write a predicate sorted(Xs) that determines if a list of numbers Xs is sorted in ascending order, and write 5 test cases for it. s o r t e d ( Xs ) :− f a l s e . %% Your code g oe s here !
Assistant
Here is the predicate sorted/1 and some test cases:
sorted([]). sorted([_]). sorted([X,Y|T]) :- X =< Y, sorted([Y|T]).
% Test cases
test1 :- sorted([1,2,3,4,5]), !. test2 :- sorted([1,3,2,4,5]), !, fail.
test3 :- sorted([-2,-1,0,1,5]), !. test4 :- sorted([5,4,3,2,1]), !, fail. test5 :- sorted([2,2,2,2,2]), !.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.