/* 5 odd cards in Picat. From Chris Smith's Maths Newsletter #553 """ I have five cards with a different odd digit on each. I'd like you to arrange these in a parot of two digit numbers with one card left on its own. Multiply the two-digit numbers and subtract the remaining cards. For example ... 13 x 57 - 9 This calculation give 732. Can you find an arrangement of this form which leads to an answer where every digits is the same? """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. import cp_utils. main => go. go ?=> N = 5, X = new_list(N), X :: [1,3,5,7,9], all_different(X), AB #= 10*X[1] + X[2], CD #= 10*X[3] + X[4], E #= X[5], % symmetry breaking AB #< CD, % Res :: 0..99999, Res #= AB * CD - E, ResA = new_list(4), ResA :: 0..9, to_num(ResA,10,Res), foreach(I in 2..4) ResA[I] #= ResA[I-1] end, Vars = X ++ ResA, solve(Vars), println(x=X), println([ab=AB,cd=CD,e=E]), println(res=Res), nl, fail, nl. go => true.