/* Enigma 95: For love and money in Picat. https://enigmaticcode.wordpress.com/2013/06/03/enigma-95-for-love-and-money/ """ Faced with seven suitable suitors, Amanda decided to mark them out of 50 for passion and out of 50 for earning power and to total the marks to find the man of her dreams. And so she did. There were no ties on either list and, when totalled, the swains came out in alphabetical order. Aloysius came 4th for love and 4th for money. Bertrand totalled 40 marks. Cuthbert was placed 2nd for love. Desmond scored 11 for money and Egbert 15 for love. Ferdie was 5th for love and scored 20 for money. Geoffrey came 6th in the money order. Someone scored for money exactly what Cuthbert scored for love. Can you reproduce all Amanda’s mark?s """ 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 = 7, People = [Aloysius,Bertrand,Cuthbert,Desmond,Egbert,Ferdie,Geoffrey], People = 1..People.len, % decision variables Love = new_list(N), Love :: 0..50, Money = new_list(N), Money :: 0..50, Total = new_list(N), Total :: 0..100, % "There were no ties on either list " all_different(Love), all_different(Money), % "and, when totalled, the swains came out in alphabetical order." all_different(Total), decreasing(Total), foreach(I in 1..N) Total[I] #= Love[I] + Money[I] end, % "Aloysius came 4th for love and 4th for money." placed(Love,Aloysius, 4), placed(Money,Aloysius, 4), % "Bertrand totalled 40 marks." Total[Bertrand] #= 40, % "Cuthbert was placed 2nd for love." placed(Love,Cuthbert,2), % "Desmond scored 11 for money" Money[Desmond] #= 11, % "and Egbert 15 for love. Love[Egbert] #= 15, % "Ferdie was 5th for love and scored 20 for money. " placed(Love,Ferdie, 5), Money[Ferdie] #= 20, % "Geoffrey came 6th in the money order. " placed(Money, Geoffrey, 6), % "Someone scored for money exactly what Cuthbert scored for love." sum([Money[I] #= Love[Cuthbert] : I in 1..N]) #= 1, Vars = Love ++ Money ++ Total, solve(Vars), println(" A B C D E F G"), println('love '=Love), println(money=Money), println(total=Total), nl, fail, nl. go => true. % % helper predicate: % person "p" is placed in "pos" in array "a" % placed(A, P, Pos) => sum([A[I] #>= A[P] : I in 1..A.len]) #= Pos.