/* Football five teams: new method (New Scientist puzzle #70) in Picat. https://enigmaticcode.wordpress.com/2017/07/12/puzzle-70-football-five-teams-new-method/ """ From New Scientist #1121, 21st September 1978 [link] The new method of rewarding goals scored in football matches goes from strength to strength. In this method 10 points are given for a win, 5 points for a draw and 1 point for each goal scored. Once can get some idea of the success of the method from the fact that in the latest competition between 5 teams, when some of the matches had been played, each team had scored at least 1 goal in every match. They are eventually going to play each other once. The points were as follows: A 11 B 8 C 12 D 5 E 43 Not more than 9 goals were scored in any match. What was the score in each match? """ 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, Points = [11,8,12,5,43], % decision variables % a match between a and b: a got scores[a,b] points and b got scores[b,a] points Scores = new_array(N,N), Scores :: 0..8, % max 8 goal per match (1+8). 0's for not played matches foreach(I in 1..N) Scores[I,I] #= 0, % a team don't play against itself foreach(J in 1..N, I < J) % a match not yet played: scores 0, % also: each teams scored at least 1 goal in every match: scores > 0 Scores[I,J] #= 0 #<=> Scores[J,I] #= 0, % no more than 9 goals was scored in each match Scores[I,J] + Scores[J,I] #<= 9 end end, % the points foreach(I in 1..N) Points[I] #= sum([ 10*(Scores[I,J] #> Scores[J,I]) + 5*((Scores[I,J] #= Scores[J,I]) #/\ Scores[I,J] #> 0) + Scores[I,J] : J in 1..N, I != J]) end, solve($[ff,split],Scores), foreach(I in 1..N, J in 1..N, I < J) if Scores[I,J] > 0 then printf("%d vs %d: %d - %d\n", I,J, Scores[I,J],Scores[J,I]) end end, nl.