Search code examples
listprologclpfd

check the list of numbers different more than one in prolog


I have a list of numbers in prolog. the numbers are already sorted.I want to check any of the numbers are not repeated and different between any two numbers is greater than one.How to check it. any idea. Thank you.

?- check([1,3,4]). %expectation
false.
?- check([2,5,7,10]). %expectation
true.


Solution

  • I assume list alreadeTry it...

    check([_]).
    check(L):-append([],[X1,X2|T],L),X1+1<X2,check([X2|T]).