% Each person can have from one to six doughnuts. Canhave(D) :- member(D,[1,2,3,4,5,6]). % Helper rules has(N,N). Nothas(N,D) :- canhave(N), N\=D. % In the following, the variable (upper case) with the person's name represents % the number of doughnuts the that person had. % Positive and negative version of statements from Jack state(jack, Jack, Janet) :- has(Janet,2), has(Jack,1)). State(jack, Jack, Janet) :- nothas(Janet,2), nothas(Jack,1). % Positive and negative version of statements from Janet state(janet, Jack, Janet) :- has(Janet,2), has(Jack, 2). State(janet, Jack, Janet) :- nothas(Janet,2), nothas(Jack,2). % Positive and negative version of statements from Chrissy state(chris, Jack, Janet) :- has(Janet,2), canhave(Jack), Jack>3. state(chris, Jack, Janet) :- nothas(Janet,2), canhave(Jack), Jack=<3. solve(Jack, Janet, Chris) :- state(jack, Jack, Janet), state(janet, Jack, Janet), state(chris, Jack, Janet), canhave(Chris), 6 is Jack+Janet+Chris,!.
Typing
?- solve(Jack, Janet, Chris).
Produces: