/* A dinner problem in SWI Prolog http://www.sellsbrothers.com/spout/#The_Logic_of_Logic """ My son came to me the other day and said, "Dad, I need help with a" "math problem." The problem went like this: * We're going out to dinner taking 1-6 grandparents, 1-10 parents and/or 1-40 children * Grandparents cost $3 for dinner, parents $2 and children $0.50 * There must be 20 total people at dinner and it must cost $20 * How many grandparents, parents and children are going to dinner? """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my SWI Prolog page: http://www.hakank.org/swi_prolog/ */ :- use_module(library(clpfd)). :- use_module(hakank_utils). go :- findall([grandparents=Grandparents, parents=Parents, children=Children], dinner([Grandparents, Parents, Children]),L), writeln(L), nl. dinner([Grandparents, Parents, Children]) :- Grandparents in 0..100, Parents in 0..100, Children in 0..100, Grandparents * 3 + Parents * 2 + Children // 2 #= 20, Grandparents + Parents + Children #= 20, % number of people = 20 % must be some of each Grandparents #> 0, Parents #> 0, Children #> 0, label([Grandparents, Parents, Children]).