Helpful Information
 
 
Category: Other Programming Languages
Prolog - Find missing elements of an ordered list

Hi,

I am trying to write a predicate that accepts a list of integers. It sorts this list and then determines if there are any gaps in the sequence:

? - game([2,6,7,5],X).
X = [3,4]

Here is what I have so far:


find_hole([],[]).

find_hole([H|T],End):-
Test is H +1,
find_hole(T,Final),
Test != Final,
Test::End.

game(List,Result) :- sort(List,Result), find_hole(Result,Done).

Any idea on what I am doing wrong?

Thanks for your help










privacy (GDPR)