/* Enigma problem 1530 (Tom Daley) in Picat. From New Scientist: """ Tom Daley Enigma 1530 Richard England, New Scientist magazine, January 28, 2009. Before being the youngest member of the British team at the 2008 Beijing Olympics, Tom Daley had become the youngest European diving champion on record by winning the individual title from the 10-metre platform board while still aged only 13. So it is appropriate that I can offer this puzzle: TOM * 13 = DALEY Each letter stands for a different digit, and no number starts with a zero. What is the five-digit number represented by DALEY? """ Compare with the Formula One model: http://www.f1compiler.com/samples/Enigma%201530.f1.html 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 = [T,O,M,D,A,L,E,Y], X :: 0..9, DALEY :: 10000..99999, TOM #= 100*T + 10*O + M, TOM * 13 #= DALEY, all_different(X), to_num([D,A,L,E,Y], 10, DALEY), T #> 0, D #> 0, Vars = X ++ [DALEY,TOM], solve(Vars), println(x=X), println([tom=TOM,daley=DALEY]), nl, fail, nl. go => true. % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).