/* Water glass riddle in Picat. From MindYourDecisions Can you solve the water glass and wine bottle riddles? https://www.youtube.com/watch?v=ex7ag9U-dzU """ [5 stacked glasses: 34 cm 2 stacked glasses: 19 cm 1 glass : ? ] How tall is one glass? """ Answer: One glass is 14cm. The non-hidden part is 5cm. Mathematica: In[1]:= Solve[{(x+y*4)==34,(x+y*1)==19}] Out[1]= {{x -> 14, y -> 5}} This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. % import mip. % Checking for a float solutions (go2/0) main => go. go ?=> X :: 1..30, % The base of the glass Y :: 1..30, % The rest of the glass, i.e. the part that's not hidden in the stack. (X + 4*Y) #= 34, (X + 1*Y) #= 19, solve($[cbc],[X,Y]), println([x=X,y=Y]), fail, nl. go => true. % Checking float version. % Same (integer) solution: 14cm and 5cm go2 ?=> X :: 1.0..30.0, % The base of the glass Y :: 1.0..30.0, % The rest of the glass, i.e. the part that's not hidden in the stack. (X + 4*Y) #= 34.0, (X + 1*Y) #= 19.0, solve($[glpk],[X,Y]), println([x=X,y=Y]), fail, nl. go2 => true.