Download
/*

  Fractions problem in Picat.

  Prolog benchmark problem (BProlog)
  """
  Find distinct non-zero digits such that the following equation holds:
         A        D        G
      ------  + ----- + ------  = 1
        B*C      E*F      H*I
  """

  Model created by Hakan Kjellerstrand, hakank@gmail.com
  See also my Picat page: http://www.hakank.org/picat/

*/

% Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/

import cp.

main => go.

go ?=>
   fractions(Digits),
   writeln(Digits),
   fail.

go => true.

fractions(Digits) =>

   Digits = [A,B,C,D,E,F,G,H,I],
   Digits :: 1..9,

   all_different(Digits),

   DD = [D1,D2,D3],
   DD :: 1..81,

   D1 #= B*C,
   D2 #= E*F,
   D3 #= H*I,
   A*D2*D3 + D*D1*D3 + G*D1*D2 #= D1*D2*D3,

   % break the symmetry
   A*D2 #>= D*D1,
   D*D3 #>= G*D2,

   %redundant constraints
   3*A #>= D1,
   3*G #=< D2,


   % search
   solve([ffc,split],Digits).