learn-prolog-now-exercises icon indicating copy to clipboard operation
learn-prolog-now-exercises copied to clipboard

Chapter 11 Subset check fix

Open nicoabie opened this issue 6 years ago • 0 comments

Hi, The solution provided will asset that subset([a,b,c,a], [a, b, c]). is true. It is missing checking that the first parameter is a set itself. Here I propose a fix using the set definition implemented in a previous chapter.

set([], []).
set([H|T], X):- member(H, T), !, set(T, X).
set([H|T], [H|X]):- set(T, X).

subset_check(SS, S):-
  set(SS, SS),
  all_members(SS, S).

all_members([], _).
all_members([H|T], S):-
  member(H, S),
  !,
  all_members(T, S)

Thanks a lot for making this repository.

nicoabie avatar Apr 06 '19 17:04 nicoabie