/* Two circle problem in Picat. From Chris Smith Math Newsletter #516 """ Two circles. Add their circumferences and you'll get 10322*Pi. Add their areas and you'l get 13946281*Pi. Can you work out the radius of each circle? """ Reminder: - Area of a circle = Pi*r^2 - Circumference = 2*Pi*r R1 = 2020 R2 = 3141 That R1 is this year and R2 is 100*Pi is of course no coincidence. :-) This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import mip. % don't work import cp. main => go. % % Integer variant (using cp). % Note: We multiply Pi and the area and circumference equations with 100. % go ?=> R1 :: 0..10000, R2 :: 0..10000, Pi = 314, % Hmm (Pi*R1*R1 + Pi*R2*R2)*100 #= Pi*13946281*100, % Area (2*Pi*R1 + 2*Pi*R2)*100 #= 10322*Pi*100, % Circumference R1 #<= R2, solve([R1,R2]), println([r1=R1,r2=R2]), fail, nl. go => true. % % Another approach. % Note: We multiply Pi and the area and circumference equations with 100. % go2 ?=> R1 :: 0..10000, R2 :: 0..10000, Pi = 314, % Hmm R1 #<= R2, area(R1,A1), area(R2,A2), circumference(R1,C1), circumference(R2,C2), 100*(A1 + A2) #= Pi*13946281*100, 100*(C1 + C2) #= 10322*Pi*100, solve([R1,R2]), println([r1=R1,r2=R2,a1=A1,a2=A2,c1=C1,c2=C2]), fail, nl. go2 => true. area(R,A) => A #= 314*R*R. circumference(R,C) => C #= 2*314*R. %% Mip version: % Give integer_expected(3.14159) % go_mip => % println(math.pi), % R1 :: 0.0..10000.0, % R2 :: 0.0..10000.0, % Pi :: 0.0..10.0, % Pi #= 3.14159, % Pi*R1*R1 + Pi*R2*R2 #= Pi*13946281.0, % 2*Pi*R1 + 2*Pi*R2 #= 10322.0*Pi, % solve([R1,R2]), % println([r1=R1,r2=R2]), % nl.