/* Enigma puzzle 1448 in Picat. Problem statement from http://www.f1compiler.com/samples/Enigma%201448.f1.html "Enigma 1448 Gwyn Owen, New Scientist magazine, June 23 2007." 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 = 4, X = new_array(N,N), X :: 0..100, Age:: 0..100, Day :: 1..31, Month :: 1..12, Year2 :: 0..99, Year :: 1900..2000, % full birth year X = {{ _, _,19, _}, {39, _, 1, 6}, { 5, 2, _, _}, { _, _, _, 2} }, % is a magic square foreach(K in 1..N) sum([X[K,I] : I in 1..N]) #= Age, sum([X[I,K] : I in 1..N]) #= Age end, % diagonals sum([X[I,I] : I in 1..N]) #= Age, sum([X[I,N-I+1] : I in 1..N]) #= Age, % calculate the age, % top row is Day, Month, 19, Year2 Day #= X[1,1], Month #= X[1,2], Year2 #= X[1,4], Year #= 100*X[1,3] + Year2, Year + Age #= 2007, Vars = X.vars ++ [Age,Day,Month,Year,Year2], solve(Vars), printf("Date: %4d-%02d-%02d\n",Year,Month,Day), foreach(Row in X) println(Row) end, nl, fail, nl. go => true.