this repo has no description
at develop 3.1 kB view raw
1/*** 2!Test 3expected: 4- !Result 5 solution: !Solution 6 D: 6 7 E: 5 8 L: 3 9 O: 9 10 ODD: 966 11 P: 1 12 PUZZLE: 102235 13 U: 0 14 Z: 2 15 num1: 161 16 num2: 635 17 num3: 805 18 num4: 483 19 x: [9, 6, 1, 0, 2, 3, 5] 20***/ 21 22% Regression test for a bug in mzn2fzn 1.2. The optimisation pass was leaving 23% dangling references to variables it had "eliminated". The symptom was the 24% following error from the FlatZinc interpreter: 25% 26% enigma_1568.fzn:28: 27% symbol error: `INT____3' undeclared 28% enigma_1568.fzn:30: 29% symbol error: `INT____3' undeclared 30% 31% (This model is from the original bug report.) 32 33% Enigma problem 1568 (Odd puzzle) in MiniZinc. 34% 35% From New Scientist 36% http://www.newscientist.com/article/mg20427311.100-enigma-number-1568.html 37% """ 38% 21 October 2009 by Albert Haddad 39% 40% Odd puzzle 41% 42% In this multiplication sum the digits have been replaced by letters and 43% dots. Different letters stand for different digits, the same letter 44% stands for the same digit, each dot can be any digit, and leading 45% digits cannot be zero. 46% 47% [ 48% . . . | num1 49% * . . . | num2 50% ------- 51% . . . | num3 52% . . . | num4 53% O D D | ODD 54% --------- 55% P U Z Z L E | PUZZLE 56% 57% ] 58% 59% What is the six-figure odd PUZZLE? 60% """ 61 62% 63% This MiniZinc model was created by Hakan Kjellerstrand, hakank@bonetmail.com 64% See also my MiniZinc page: http://www.hakank.org/minizinc 65% 66include "globals.mzn"; 67 68int: n = 7; % number of unknown 69set of int: Digits = 0..9; 70var Digits: O; 71var Digits: D; 72var Digits: P; 73var Digits: U; 74var Digits: Z; 75var Digits: L; 76var Digits: E; 77array[1..n] of var Digits: x; 78 79var 100..999: num1; 80var 100..999: num2; 81var 100..999: num3; 82var 100..999: num4; 83var 100..999: ODD ; 84var 100000..999999: PUZZLE; 85 86predicate cp1d(array[int] of var int: x, array[int] of var int: y) = 87 assert(index_set(x) = index_set(y), 88 "cp1d: x and y have different sizes", 89 forall(i in index_set(x)) ( x[i] = y[i] ) ) 90; 91 92 93% solve satisfy; 94solve :: int_search( 95 x ++ [num1,num2,num3,num4,ODD,PUZZLE], 96 first_fail, 97 indomain_min, 98 complete) 99 satisfy; 100 101constraint 102 cp1d(x, [O,D,P,U,Z,L,E]) /\ 103 104 all_different(x) /\ 105 106 ODD = 100*O + 10*D + D /\ 107 PUZZLE = 100000*P + 10000*U + 1000*Z + 100*Z + 10*L + E /\ 108 109 num1 * num2 = num3 + num4*10 + ODD*100 /\ 110 PUZZLE = num1 * num2 /\ 111 112 PUZZLE mod 2 = 1 /\ % PUZZLE is odd 113 114 % And then code the "long multiplication" 115 num1 * (num2 mod 10) = num3 /\ 116 num1 * ((num2 div 10) mod 10) = num4 /\ 117 num1 * (num2 div 100) = ODD 118; 119 120output [ 121 "O = ", show(O), ";\n", 122 "D = ", show(D), ";\n", 123 "P = ", show(P), ";\n", 124 "U = ", show(U), ";\n", 125 "Z = ", show(Z), ";\n", 126 "L = ", show(L), ";\n", 127 "E = ", show(E), ";\n", 128 "x = ", show(x), ";\n", 129 "num1 = ", show(num1), ";\n", 130 "num2 = ", show(num2), ";\n", 131 "num3 = ", show(num3), ";\n", 132 "num4 = ", show(num4), ";\n", 133 "ODD = ", show(ODD), ";\n", 134 "PUZZLE = ", show(PUZZLE), ";\n" 135];