berghallen
Programmer
I have write a program in Prolog, that will look in a list of ingredients and compare if you need to buy or what you can cook with all the ingredients you got home.
I have finish the first one that looks if I can cook for example rise. But I need to write a program that calculate how much I must buy to be able to cook the food.
The code so far, and I know that everything under buy isn't correct.
at_home([ingredient(rice,2), ingredient(water,10), ingredient(salt, 4), ingredient(pepper, 9), ingredient(milk, 1), ingredient(curry, 4)]).
recipe(rice,[ingredient(rice,4),ingredient(salt,3),ingredient(water,5)]).
recipe(chicken,[ingredient(chicken,2),ingredient(salt,1),ingredient(pepper,1)]).
recipe(currymix,[ingredient(curry,3),ingredient(salt,1),ingredient(pepper,2),ingredient(water,2)]).
cook(X) :- at_home(YS), recipe(X,XS), kollacook(XS,YS).
kollacook([],_).
kollacook([X|XS],YS) :- tillrackligt(X,YS), kollacook(XS,YS).
tillrackligt(ingredient(V,T1),[ingredient(V,T2)|_]) :- T1 =< T2.
tillrackligt(I,[_|YS]) :- tillrackligt(I,YS).
buy(X, L) :- at_home(YS), recipe(X,XS), kollabuy(XS, YS, L).
kollabuy([], _, _).
kollabuy([X|XS], YS, L) :- kopa(X, YS, L), kollabuy(XS, YS, L).
kopa(ingredient(_, X), [], L) :- L is X.
kopa(ingredient(V, T1), ingredient(V,T2)|_, L) :- T1>T2, L is T1-T2.
kopa(X, ingredient(_,_)|TS, L) :- kopa(X, TS, L).
I have finish the first one that looks if I can cook for example rise. But I need to write a program that calculate how much I must buy to be able to cook the food.
The code so far, and I know that everything under buy isn't correct.
at_home([ingredient(rice,2), ingredient(water,10), ingredient(salt, 4), ingredient(pepper, 9), ingredient(milk, 1), ingredient(curry, 4)]).
recipe(rice,[ingredient(rice,4),ingredient(salt,3),ingredient(water,5)]).
recipe(chicken,[ingredient(chicken,2),ingredient(salt,1),ingredient(pepper,1)]).
recipe(currymix,[ingredient(curry,3),ingredient(salt,1),ingredient(pepper,2),ingredient(water,2)]).
cook(X) :- at_home(YS), recipe(X,XS), kollacook(XS,YS).
kollacook([],_).
kollacook([X|XS],YS) :- tillrackligt(X,YS), kollacook(XS,YS).
tillrackligt(ingredient(V,T1),[ingredient(V,T2)|_]) :- T1 =< T2.
tillrackligt(I,[_|YS]) :- tillrackligt(I,YS).
buy(X, L) :- at_home(YS), recipe(X,XS), kollabuy(XS, YS, L).
kollabuy([], _, _).
kollabuy([X|XS], YS, L) :- kopa(X, YS, L), kollabuy(XS, YS, L).
kopa(ingredient(_, X), [], L) :- L is X.
kopa(ingredient(V, T1), ingredient(V,T2)|_, L) :- T1>T2, L is T1-T2.
kopa(X, ingredient(_,_)|TS, L) :- kopa(X, TS, L).