/* GATHER + HOMAGE = MARTIN in Picat. From CelebrationOfMind Google Hangout 20131021 Gathering for Gardner GATHER + HOMAGE = MARTIN AxA = H G X G = O Here's the unique solution: x: [3, 2, 7, 4, 6, 5, 9, 8, 0, 1] G: 3 A: 2 T: 7 H: 4 E: 6 R: 5 O: 9 M: 8 I: 0 N: 1 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 = [G,A,T,H,E,R,O,M,I,N], X :: 0..9, all_different(X), 100000*G + 10000*A + 1000*T + 100*H + 10*E + R + 100000*H + 10000*O + 1000*M + 100*A + 10*G + E #= 100000*M + 10000*A + 1000*R + 100*T + 10*I + N, % These are not needed for uniqueness A*A #= H, G*G #= O, % The first digits in each word must not be 0. % (though it don't make any difference for the solution). G #> 0, H #> 0, M #> 0, solve(X), println(X), println([G,A,T,H,E,R]), println([H,O,M,A,G,E]), println([M,A,R,T,I,N]), nl, fail, nl. go => true. % % Lookup = lookup(L,Ix) % Lookup = L.lookup(Ix) % % returns a list where the indices in A[I] is looked up in L. % lookup(L,Ix) = [ L[Ix[I]] : I in 1..Ix.len ] => println($lookup(L,Ix)).