# Cristiano Ronaldo's soccer puzzle

Yesterday evening, Cristiano Ronaldo looked into a newspaper and quickly detected the sports section. After fifteen minutes of reading and studying, Cristiano bitterly complained about the minimal amount of information provided by modern soccer tables. Here are the first few lines of the current table of the Spanish soccer league:

          Team            M   Pts  GD
----------------------------------
1.  Villarreal      7   16   +7
2.  Real Madrid     7   15  +13
3.  Celta de Vigo   7   15   +8


Clearly the column M contains the number of matches played so far, the column Pts contains the number of points reached so far, and the column GD contains the current goal difference.

But what Cristiano really wants to know is the number W of won, the number L of lost, and the number D of drawn matches. And (according to Cristiano) there is no way of deducing these numbers from the information provided in the table.

Gareth Bale (who is mathematically gifted) observed that for Villarreal the numbers actually can be deduced: W=5, L=1, and D=1. On the other hand, for Celta there exist two different possible number triples.

Question: From which combinations of two non-negative integers M and Pts can one uniquely determine the three numbers W, L and D?

Note: For a win/loss/draw a team respectively scores 3/0/1 points.

Let $P=$ Pts. We are looking for nonnegative integer solutions to the equations $$3W+D=P\qquad \qquad W+L+D=M$$ Once $W$ is chosen, the unique choices for $D$ and $L$ which make the above true are $D=P-3W$ and $L=M-P+2W$. Using the inequalities $W,D,L\ge0$, there is a solution as long as $W$ is an integer in the below range: $$\max(0,\tfrac{P-M}2)\le W\le \tfrac{P}3$$ This means there is a unique solution if and only if these two bounds are equal, so when

$$\lfloor{\tfrac{P}3}\rfloor=0 \quad \text{or}\quad \lfloor\tfrac{P}3\rfloor=\lceil\tfrac{P-M}2\rceil.$$

When $P\le 2$, the left inequality holds, so $M$ can be anything.

When $P\ge 3$, the right equality implies that $P-M$ is either equal to $2\lfloor\tfrac{P}3\rfloor$ or $2\lfloor\tfrac{P}3\rfloor-1$.

Thus, we get that there is a unique solution if and only if $$P\le 2 \quad \text{or} \quad M-P+2\lfloor\tfrac{P}3\rfloor=0\text{ or }1$$ For example, in the Villarreal case, $7-16+2\lfloor\tfrac{16}3\rfloor=1$, so there is a unique solution. For Celta, $7-15+2\lfloor\tfrac{15}3\rfloor=2$, so there are multiple solutions.

For any Number M if

$Pts=(M*3)$

or

$(((M-2)*3)+1)<=Pts<=((M*3)-2)$

or

$Pts=(((M-2)*3)-1)$

or

$0<=Pts<=2$

there exists exactly one solution.

Pts = M*3 ->
W=M L=0 D=0

Pts = M*3-1 ->
not possible

Pts = M*3-2 ->
W=M-1 L=0 D=1

Pts = (M-1)*3 ->
W=M-1 L=1 D=0

Pts = (M-1)*3-1 ->
W=M-2 L=0 D=2

Pts = (M-1)*3-2 ->
W=M-2 L=1 D=1

Pts = (M-2)*3 ->
either W=M-2 L=2 D=0
or     W=M-3 L=0 D=3

Pts = (M-2)*3-1 ->
W=M-3 L=1 D=2

For everything below as long as you have at least 2 defeats and one win
you can exchange them with 3 draws.
This goes for all combinations except:

Pts = 0 ->
W=0 L=M D=0

Pts = 1 ->
W=0 L=M-1 D=1

Pts = 2 ->
W=0 L=M-2 D=2


Of course i excluded all combinations that are obviously impossible with:

$Pts>(M*3)$

If you want to add 7 numbers out of 3/0/1 to 15, there are only two ways to go: 3,3,3,3,3,0,0 and 3,3,3,3,1,1,1. So the possible solutions are W=5, L=2, D=0 and W=4, L=0, D=3.

/edit: oops, a more general solution was asked for. So ignore me :-)