/* Six triangle puzzle in Picat. From Chris Smith Math Newsletter #546 """ Find me six right-angled triangles with integer sides and the same perimenter! """ (I assume that this means six _different_ triangles.) There's a lot of different solutions. Here is one solution (with the smallest Perimeter): perimeter = 120 [20,48,52] [24,45,51] [30,40,50] [40,30,50] [45,24,51] [48,20,52] where [20,48,52] = [A,B,C] => A*A + B*B == C*C This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. import util. import cp. main => go. go ?=> L = new_list(6*3), % 6 triangles L :: 1..1000, Perimeter :: 1..10000, LL = chunks_of(L,3), foreach([A,B,C] in LL) A*A+B*B #= C*C, A+B+C #= Perimeter end, TT = [T : [A,B,C] in LL, T #= A*100+B*10+C], all_different(TT), increasing(TT), Vars = L ++ TT ++ [Perimeter], % solve($[min(Perimeter)],Vars), % smallest perimeter solve($[],Vars), println(perimeter=Perimeter), % println(L), % println([A*100+B*10+C : [A,B,C] in LL]), println("The triangles:"), foreach([A,B,C] in LL) println([A,B,C]) end, nl, fail, nl. go => true.