Download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 
  Fractions problem in SICStus Prolog.
 
  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 SICStus Prolog page: http://www.hakank.org/sicstus/
 
*/
 
% Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/
 
:-use_module(library(clpfd)).
:-use_module(library(lists)).
 
go :-
        findall(Digits,fractions(Digits), List),
        ( foreach(L,List) do
              write(L),nl
        ),
        fd_statistics.
 
fractions(Digits) :-
 
        Digits = [A,B,C,D,E,F,G,H,I],
        domain(Digits,1,9),
 
        DD = [D1,D2,D3],
        domain(DD,1,81),
 
        all_distinct(Digits),
 
        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
        append(Digits,DD,Vars),
        labeling([min,step,up], Vars).