/* Martin Gardner's Prime puzzle in Picat. """ Name : gardner.pl Title : Gardner's prime puzzle problem Original Source: Daniel Diaz - INRIA France Adapted by : Daniel Diaz for GNU Prolog Date : February 1997 Solve the operation: mP where tP is a string of t prime digits (2,3,5 or 7) x nP -------- = (m+n)P """ 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 ?=> M = 4, N = 3, P = [2,3,5,7], MP :: 1000..9999, MPA = new_list(M), MPA :: P, NP :: 100..999, NPA = new_list(N), NPA :: P, MNP :: 1000000..9999999, MNPA = new_list(M+N), MNPA :: P, to_num(MPA,10,MP), to_num(NPA,10,NP), to_num(MNPA,10,MNP), MP * NP #= MNP, Vars = MPA ++ NPA ++ MNPA, solve(Vars), printf("%d * %d = %d\n", MP,NP,MNP), 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]).