/* Enigma 1575 (All our days) in Picat. Problem formulation from Formula1 Compiler: http://www.f1compiler.com/samples/Enigma%201575.f1.html """ Enigma 1575 Adrian Somerfield, New Scientist magazine, December 12, 2009. I have written the days of the week with their ordinal numbers as shown: MO TU W TH F SA SU 1 2 3 4 5 6 7 Letters being consistently replaced by non-zero digits, each day is divisible by its own ordinal number (and by no higher digit). Please send in the FAMOUS number. """ FAMOUS = 528941 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 ?=> Letters = [M,O,T,U,W,H,F,S,A], Letters :: 1..9, Days = new_list(7), Days :: 0..99, FAMOUS #= F*100000 + A*10000 + M*1000 + O*100 + U*10 + S, all_different(Letters), Days[1] #= 10*M + O, Days[2] #= 10*T + U, Days[3] #= W, Days[4] #= 10*T + H, Days[5] #= F, Days[6] #= 10*S + A, Days[7] #= 10*S + U, foreach(I in 1..7) % is divisible by its own ordinal number Days[I] mod I #= 0, % and by no higher digit foreach(J in I+1..9, J =< 9) Days[I] mod J #!= 0 end end, Vars = Letters ++ Days ++ [FAMOUS], solve(Vars), println(famous=FAMOUS), println(letters=Letters), println(days=Days), nl, fail, nl. go => true.