/* Jellybeans problem in Picat. http://l4f.cecs.anu.edu.au/puzzles/beginner/jellybeans """ There are four children, Alice, Boris, Claire and David. Their ages (not in order) are 6, 7, 8 and 9. Each child has either 1, 2, 3 or 4 jellybeans (a different number each). 1. Alice’s age plus her beans is the same as Boris’s age plus his beans. 2. Claire’s age is two more than the number of Alice’s beans. 3. Alice’s age is equal to the number of beans she and Claire have altogether. How old is David, and how many beans has he? """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 4, People = [Alice, Boris, Claire, David], People = 1..N, AgeSet = [6,7,8,9], BeanSet = [1,2,3,4], Age = new_list(N), Age :: AgeSet, Beans = new_list(N), Beans :: BeanSet, all_different(Age), all_different(Beans), % 1. Alice’s age plus her beans is the same as Boris’s age plus his beans. Age[Alice] + Beans[Alice] #= Age[Boris] + Beans[Boris], % 2. Claire’s age is two more than the number of Alice’s beans. Age[Claire] #= Beans[Alice] + 2, % 3. Alice’s age is equal to the number of beans she and Claire have altogether. Age[Alice] #= Beans[Alice] + Beans[Claire], Vars = Age ++ Beans, solve(Vars), println(age=Age), println(beans=Beans), nl, fail, nl. go => true.