/* Four rectangle problem in Picat. https://mindyourdecisions.com/blog/2017/12/20/can-you-solve-the-rectangle-area-puzzle/ """ A large rectangle is divided into four rectangles, three of which have areas 16, 13, and 39 as drawn in the following figure: [ x len -------------- | 13 | 39 | -------------- y | 16 | ? | -------------- height ] What is the area of the fourth rectangle """ 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 ?=> L = [Area1,Area2,Area3,Area4,Len,Height,X,Y], L :: 1..100, Area1 #= 13, Area2 #= 39, Area3 #= 16, X*Y #= Area1, (Len-X)*Y #= Area2, (Height-Y)*X #= Area3, (Height-Y)*(Len-X) #= Area4, (Len*Height) #= Area1+Area2+Area3+Area4, solve(L), println(area4=Area4), println([area1=Area1,area2=Area2,area3=Area3,area4=Area4,len=Len,height=Height,x=X,y=Y]), fail, nl. go => true.