/* Enigma Number 1573 (Sat, Sun, Mon, Tue) in Picat. From New Scientist http://www.newscientist.com/article/mg20427360.800-enigma-number-1573.html """ 25 November 2009 by Albert Haddad Sat, Sun, Mon, Tue Four consecutive days are noted in the two multiplication sums shown on the right, where different letters stand for different digits, the same letter stands for the same digit, each dot can be any digit, and leading digits cannot be zero. Assuming that a MONTH is exactly divisible by each of 28, 30 and 31, what is the numerical total of the two five-digit products? [The figure is S A T M O N * . . * . . ------- ------- . . . . . . . . . . . . . . . . --------- --------- S U N . . T U E . . ] """ Note: I first send in a solution, and then I changed the model slightly which now finds two solutions (of my first is one). These two solutions finds the same MONTH but the two 5-digit numbers are different, and hence the total. The founds solutions are: a) This is the one I send to New Scientist [S, A, T, M, O, N, U, E] x: [3, 5, 2, 7, 8, 1, 4, 9] SAT: 352 MON: 781 MONTH = 78120 SUNab = 34144 TUEcd = 24992 total = 59136 b) [S, A, T, M, O, N, U, E] x: [4, 6, 2, 7, 8, 1, 0, 3] SAT: 462 MON: 781 MONTH = 78120 SUNab = 40194 TUEcd = 20306 total = 60500 Note that MONTH is the same in the two solutions (as is H, namely 0). This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> X = [S,A,T,M,O,N,U,E], X :: 0..9, % This could be anything (happens to be 0) H :: 0..9, % Tmp variables: % a and b is the last two digits in SUNab % c and d is the last two digits in TUEcd AA :: 0..9, B #= SAT1 mod 10, % b is also the last digit in SAT1 C :: 0..9, D #= MON1 mod 10, % d is also the last digit in MON1 SAT #= 100*S + 10*A + T, SAT_TMP :: 10..99, % SAT1 = SAT * last digit in SAT_tmp % SAT2 = SAT * first digit in SAT_tmp SAT1 #= SAT*(SAT_TMP mod 10), SAT2 #= SAT*(SAT_TMP div 10), MON #= 100*M + 10*O + N, MON_TMP :: 10..99, % MON1 = MON * last digit in MON_tmp % MON2 = MON * first digit in MON_tmp MON1 #= MON*(MON_TMP mod 10), MON2 #= MON*(MON_TMP div 10), SUNab #= 10000*S + 1000*U + 100*N + 10*AA + B, TUEcd #= 10000*T + 1000*U + 100*E + 10*C + D, MONTH #= 10000*M + 1000*O + 100*N + 10*T + H, Total #= SUNab + TUEcd, all_different(X), S #> 0, T #> 0, SUNab #= SAT * SAT_TMP, TUEcd #= MON * MON_TMP, SUNab #= SAT1 + SAT2*10, TUEcd #= MON1 + MON2*10, MONTH mod 28 #= 0, MONTH mod 30 #= 0, MONTH mod 31 #= 0, solve(X), println(x=X), println(month=MONTH), println(sunab=SUNab), println(tuecd=TUEcd), println(total=Total), nl, fail, nl. go => true.