/* Three pile of matches in Picat. From https://stackoverflow.com/questions/76283366/how-to-formulate-this-simple-mathematical-riddle-in-wolfram-language """ Place three piles of matches on a table, one with 11 matches, the second with 7, and the third with 6. You are to move matches so that each pile holds 8 matches. You may add to any pile only as many matches as it already contains, and all the matches must come from one other pile. For example, if a pile holds 6 matches, you may add 6 to it, no more or less. You have three moves. ... However, there does exist a solution. The solution is: * Move 7 matches from the pile with 11 matches to the pile with 7 matches. The piles now contain 4, 14, and 6 matches. * Move 6 matches from the pile with 14 matches to the pile with 6 matches. The piles now contain 4, 8, and 12 matches. * Move 4 matches from the pile with 12 matches to the pile with 4 matches. The piles now contain 8, 8, and 8 matches. Is there a way to formulate the question so that this is computable with Wolfram Language? """ This planner model shows the (unique) solution: [From = [11,7,6],move,7,from,1,to,2,To = [4,14,6]] [From = [4,14,6],move,6,from,2,to,3,To = [4,8,12]] [From = [4,8,12],move,4,from,3,to,1,To = [8,8,8]] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import planner. main => go. go ?=> Init = [11,7,6], best_plan_nondet(Init,Plan), foreach(P in Plan) println(P) end, nl, fail, nl. go => true. final(L) :- L = [8,8,8]. action(From,To,Move,1) :- select(F,1..3,Rest), From[F] > 0, select(T,Rest,Last), From[F] - From[T] >= 0, To = new_list(3), To[F] = From[F] - From[T], To[T] = From[T] + From[T], To[Last[1]] = From[Last[1]], Move = ['From'=From,move,From[T],from,F,to,T,'To'=To].