-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmixologician.dl
60 lines (45 loc) · 1.94 KB
/
mixologician.dl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.type Ingredient <: symbol
.type Recipe <: symbol
.decl Has(x : Ingredient)
.input Has(filename="bar")
.decl Needs(drink : Recipe, ingredient : Ingredient)
.input Needs(filename="recipes", delimiter=" <- ")
.decl Begets(in : Ingredient, out : Ingredient)
.input Begets(filename="begets", delimiter=" -> ")
.input Begets(filename="auto-begets", delimiter=" -> ")
.decl Composite(result : Ingredient, first : Ingredient, second : Ingredient)
.input Composite(filename="combinations", delimiter=", ")
.decl IsRecipe(x : Recipe)
IsRecipe(x) :- Needs(x, _).
.decl IsIngredient(x : Ingredient)
IsIngredient(x) :- Needs(_, x).
IsIngredient(x) :- Begets(x, _).
IsIngredient(x) :- Begets(_, x).
IsIngredient(x) :- Composite(x, _, _).
IsIngredient(x) :- Composite(_, x, _).
IsIngredient(x) :- Composite(_, _, x).
.decl Unbuyable(x : Ingredient)
.input Unbuyable(filename="unbuyable")
.input Unbuyable(filename="auto-unbuyable")
Begets(x, x) :- IsIngredient(x).
Begets(x, z) :- Begets(x, y), Begets(y, z).
Has(out) :- Has(in), Begets(in, out).
Begets(x, result) :- Composite(result, first, second), Has(first), Begets(x, second).
Begets(x, result) :- Composite(result, first, second), Has(second), Begets(x, first).
.decl Missing(drink : Recipe, ingredient : Ingredient)
Missing(drink, ingredient) :- Needs(drink, ingredient), !Has(ingredient).
.decl Mixable(drink : Recipe)
Mixable(drink) :- IsRecipe(drink), !Missing(drink, _).
.decl MixableRecipe(drink : Recipe, ingredient : Ingredient)
MixableRecipe(drink, recipe) :- Mixable(drink), Needs(drink, recipe).
.decl Enables(missing : Ingredient, drink : Recipe)
Enables(ingredient, drink) :-
!Unbuyable(ingredient),
Missing(drink, out),
Begets(ingredient, out),
count : { Missing(drink, _) } =
count : { Begets(ingredient, product), Missing(drink, product) }
.
.output Mixable(filename="mixable")
.output MixableRecipe(filename="mixable-recipes", delimiter=" <- ")
.output Enables(filename="shopping-list", delimiter=" -> ")