All pastes #364043 Raw Edit

Plouj

public text v1 · immutable
#364043 ·published 2007-02-19 21:50 UTC
rendered paste body
/** ---------------------------------------------------------
  holds if all elements of the list are sorted
  (in a descending order) without gaps:
  given any element A, the next element is strictly A-1
  additionally, the last element has to be 1
  ---------------------------------------------------------- */

properly_ordered([A, B|R]) :- B is A - 1, properly_ordered([B|R]).
properly_ordered([A]) :- A is 1.


PROLOG SESSION:
?- properly_ordered([1, 2, 3]).

No
?- properly_ordered([3, 2, 1]).

Yes