/* Twin letters in Picat. From http://www.comp.nus.edu.sg/~henz/projects/puzzles/digits/index.html """ Twin Letters In the following puzzle, there are ten pairs of letters to be assigned to the same digit so that the multiplication (including intermediate results) is correct. Can you find out the pairs and their values? A B C * D E F ____________ G H I J K L M N O ____________ P Q R S T Q=R=0, D=H=1, A=B=2, J=M=3, C=P=4, K=N=5, I=T=6, E=G=7, L=O=8, F=S=9 224 * 179 _________ 716 358 358 _________ 40096 """"" Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => LD = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T], twin(LD), println([a=A,b=B,c=C,d=D,e=E,f=F,g=G,h=H,i=I,j=J]), println([k=K,l=L,m=M,n=N,o=O,p=P,q=Q,r=R,s=S,t=T]), Alpha = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t], Len = length(LD), foreach(CC in 0..9, {El,II} in zip(LD,1..Len)) if El == CC then printf("%d:%w ",CC,Alpha[II]) end end, nl. twin(LD) => LD = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T], LD :: 0..9, C1 :: 0..1, C2 :: 0..2, C3 :: 0..1, % exactly 2 occurrences of each digit foreach(CC in 0..9) count(CC,LD,#=,2) end, 100*G + 10*H + I + 1000*J + 100*K + 10*L + 10000*M + 1000*N + 100*O #= 10000*P + 1000*Q + 100*R + 10*S + T, (100*D + 10*E + F)*C #= 100*G + 10*H + I, (100*D + 10*E + F)*B #= 100*J + 10*K + L, (100*D + 10*E + F)*A #= 100*M + 10*N + O, (100*A + 10*B + C) * (100*D + 10*E + F) #= 10000*P + 1000*Q + 100*R + 10*S + T, % Carry restrictions T #= I, S + 10*C1 #= H + L, R + 10*C2 #= G + K + O + C1, Q + 10*C3 #= J + N + C2, P #= M + C3, solve(LD), solve([C1,C2,C3]).