/* Wee equation in Picat. From Chris Smith's Math Newletter #549 """ Please find me the value of the positive integers a,b,d,d that satisfy this wee equation a + 1 = 266/115 ---- b + 1 ------ c + 1/d """ (Wee (Scottish): little) There's a single solution: [2,3,5,7] Mathematica give this unique solution: In[1]:= FindInstance[{a + (1/(b + 1/(c + 1/d))) == 266/115, a > 0, b > 0, c > 0, d > 0}, {a, b, c, d} \[Element] Integers, 10] Out[1]= {{a -> 2, b -> 3, c -> 5, d -> 7}} This 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 = [A,B,C,D], L :: 1..100, % A + 1 / (B + 1 / ( C + 1/D)) #= 266/115, % % However, using "/" is not a good thing so we rewrite % to just additions and multiplications. % % Mathematica: % In[2]:= Factor[A + 1 / (B + 1 / ( C + 1/D)) == 266/115] % % 1 + A B + A D + C D + A B C D 266 % Out[2]= ----------------------------- == --- % B + D + B C D 115 % T1 #= 1 + A*B + A*D + C*D + A*B*C*D, T2 #= B + D + B*C*D, % T1 / T2 #= 266/115, T1*115 #= T2*266, solve($[degree,updown],L), println(L), fail, nl. go => true.