1. Given a list of integers, your prolog program must figure out whether there a
ID: 3629255 • Letter: 1
Question
1. Given a list of integers, your prolog program must figure out whether there are missing integers in the given set of integers and report a list of all values that are missing. The integers will always be greater than zero, but not necessarily in order. No integer will be repeated in the list. Prolog should answer with a list of integers missing, or the null list if no hole exists.Examples: ?- findmissing([3,1,4,6,5],X). X = [2] ?- findmissing([3,1,2,4],X). X = [] ?- findmissing([2,6,7,5],X). X = [3,4] The built in predicate sort might be used to simplify the solution.
Explanation / Answer
try with the followingfind_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).
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).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.