/* Stolen bag of marbles in Picat. From Muhammad Zain Sarwar "Can You Solve This Triangular Numbers Puzzle?" https://medium.com/puzzle-sphere/can-you-solve-this-triangular-numbers-puzzle-0f20f90c1168 """ In the mysterious town of Numerville, where numbers weren't just for counting — they held hidden secrets. Professor Arithmo had a peculiar habit of collecting marbles and storing them in 15 special bags, each having a unique number of marbles in it. His collection was perfectly arranged and following a mathematical pattern known only to him. One morning a thief broke in and one of the bags was missing! Strangely, the professor could not recall the total number of marbles he had before the theft. The professor who was a lover of numbers, immediately set out to solve the mystery. When he counted the remaining marbles, he noticed that the [thief] left behind marbles seemed to form a special mathematical pattern. The thief left behind a mathematical clue which suggests the new sum of all marbles in the bags is a triangular number. [... Description of triangular numbers. ...] Puzzle Statment Professor originally had 15 bags having a different number of marbles in them. These marbles are following a sequence from 0 to 14. After the theft, one bag of marbles was missing but the remaining marbles formed a special mathematical pattern. However, he did not remember the original total, he had to use mathematical reasoning to find the missing marbles. ... Thus, the thief stole a bag with 14 marbles in it, leaving exactly 91 marbles behind, which is another triangular number. """ This model gives two solutions: * [b1 = 15,n1 = 105,b2 = 14,n2 = 91,s = 14] The intended solution: The thief stole the 14 marble bag * [b1 = 15,n1 = 105,b2 = 15,n2 = 105,s = 0] Another solution: The thief stole the bag with 0 marbles. I haven't seen any mention that any _marbles_ were missing, just one bag of marbles were missing. This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go ?=> [B2,N1,N2,S] :: 0..1000, B1 = 15, % Original number of bags S :: 0..14, % One of the 14 bags with S marbles was stolen tri(B1,N1), % number of marbles before N2 #= N1-S, % the number of marbles after tri(B2,N2), % the number of marbles after is also a tri number solve([N1,B1,N2,B2,S]), println([b1=B1,n1=N1,b2=B2,n2=N2,s=S]), fail, nl. go => true. tri(B,N) => 2*N #= B*(B-1).