Skip to content

Instantly share code, notes, and snippets.

@reiddraper
Created May 1, 2011 20:35
Show Gist options
  • Save reiddraper/950847 to your computer and use it in GitHub Desktop.
Save reiddraper/950847 to your computer and use it in GitHub Desktop.
prolog cocktails
any([X|Y], R) :- member(X, R).
any([X|Y], R) :- any(Y, R).
all([X|Y], R):- member(X, R), all(Y,R).
all([], _).
cocktail(martini).
cocktail(martinez).
cocktail(manhattan).
cocktail(ginmule).
ingredient(a).
ingredient(b).
ingredient(c).
ingredient(d).
ingredients(martini, [a, b]).
ingredients(martinez, [a, b, c]).
ingredients(manhattan, [b, d]).
ingredients(ginmule, [c, b]).
canMake(Ingredients, X, Y):-
cocktail(X),
cocktail(Y),
\+ X = Y,
ingredients(X, I),
all(I, Ingredients),
ingredients(Y, T),
all(T, Ingredients).
three(A, B, C, X, Y, Z):-
cocktail(X),
cocktail(Y),
cocktail(Z),
ingredient(A),
ingredient(B),
ingredient(C),
\+ A = B,
\+ A = C,
\+ B = C,
\+ X = Y,
\+ X = Z,
\+ Y = Z,
ingredients(X, T),
all(T, [A, B, C]),
ingredients(Y, R),
all(R, [A, B, C]),
ingredients(Z, S),
all(S, [A, B, C]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment