/* Enigma puzzle Five fives (#1358) in Picat. Problem formulation from http://www.f1compiler.com/samples/Enigma%201358.f1.html """ Five fives Enigma 1358 Adrian Somerfield, New Scientist magazine, September 17, 2005. You might think there is something wrong with the addition sum shown below, but in fact each of the five numbers shown in the sum is in a different base. 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 --------- 1 1 1 0 1 All five numbers are even and the given total at the bottom is less than 100,000. What is that total? """ 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 ?=> N = 5, NumBases = 20, % 2..20 Bases = new_list(N), Bases :: 2..NumBases, X = new_list(N), X :: 0..100000, % find the bases foreach(I in 1..N) to_num([1,1,1,0,1], Bases[I],X[I]), X[I] mod 2 #= 0 end, % bases are different all_different(Bases), % calculate the sum X[N] #= sum(X[1..N-1]), % symmetry breaking increasing(Bases), Vars = Bases ++ X, solve(Vars), println(x=X), println(bases=Bases), 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]). to_num(List,Base) = Num => to_num(List, Base, Num).