Translate riddle to math

I have already solved this riddle, but I didn't like the method I had to use and would like to be able to solve it with more mathematical rigor.

I understand the basic idea for a problem like this: come up with a system of equations with at least as many equations as there are variables. But, I found myself having a hard time translating a portion of this riddle into algebra and had to resort to trying out values to find the solution. There has to be a better way, and that is what I'm looking for: how to rigorously express the portion of this riddle I am missing so that I can solve for it instead of experimentally plugging in values until all the equations are satisfied. Here is the riddle:

I'm thinking of four numbers:

• Rule 1: The sum of all four numbers is 31
• Rule 2: Only one of the four is an odd number
• Rule 3: The highest number minus the lowest number is 7
• Rule 4: The difference between the two middle numbers is 2
• Rule 5: There are no duplicate numbers

Which four numbers are they?

• From Rule 2, I defined A as the odd number, and B, C, and D as the even numbers
• Arbitrarily, I assigned B < C < D (we can do this because there are no repeats)
• From Rule 1, I defined A + B + C + D = 31
• From Rule 5: I get A != B != C != D (using != to convey not equal)
• From Rule 4, I get C - B = 2
• From Rule 2 and 4, I know B is even and C is even, leaving A and D, one of which is odd, the other even. I have defined D as even, so A must be odd.
• At this point I don't know which is bigger, A or D, but I do know that A < B or A > D, one of the two.
• From Rule 3, D - A = 7 or D - B = 7, but since I know D - B is an even number, I now know A < B < C < D < 31
• Rearrange C = B + 2 and D = A + 7
• Substituting, I know A + 2B + D = 29, and then 2A + 2B = 22
• Divide by 2 to get A + B = 11
• With the constraints that A is odd and B is even, that leaves only three possibilities for A and B: 1 + 10 or 3 + 8 or 5 + 6 Note that this is the step I don't like. I think there should be a better way to figure it out, rather than plugging in values. What am I missing? Probably something super simple.
• Trying all three of these combinations leads to A=1 B=10 C=12 D=8, which violates the total-order scheme I set up (arbitrarily), or A=3 B=8 C=10 D=10 which violates Rule 5, or A=5 B=6 C=8 D=12, which obeys all the rules and sums to 31.

So that's how I got the answer of 5, 6, 8, and 12. But there has to be a more robust way to solve this. Please show me. High school was a long time ago. I'm probably just forgetting something basic.

• To be honest, I pretty much like the way you solved this. You did a lot of smart work to end up with only three cases. I think that should be considered a success. – Greg Martin Nov 10 '16 at 7:50

Let the two smallest numbers be $a$ and $b$; the other two are $b+2$ and $a+7$. The sum of all four numbers is $31$, this simplifies to $a+b=11$. Since only one of the four numbers is odd, and $b$ and $b+2$ have the same parity, $a$ is odd. The four numbers are then, in increasing order, $$a<11-a<13-a<a+7$$ The last inequality simplifies to $a>3$, and the first to $a<{11\over 2}$. The only odd number in this interval is $a=5$.

There is an inherent indeterminancy because there are $4$ variables and only $3$ equations, but it "happens" that the solution is unique because of the other "soft" constraints.

For a slightly more direct derivation, let $a \gt b \gt c \gt d$ be the numbers (with the inequalities being strict because of Rule 5 "no duplicates") then the premise translates to:

\begin{align} & a+b+c+d=31 \tag{1} \\ & a-d=7 \tag{2} \\ & b-c=2 \tag{3} \end{align}

Solving the above with $d$ as a free variable i.e. substituting $(2)$ $a=d+7$ and $(3)$ $b = c+2$ gives:

$$d+7 + c + 2 + c + d = 31$$ $$2 c = 22 - 2 d$$

Then:

\begin{align} & c = 11 - d \\ & b = 13 - d \\ & a = d + 7 \end{align}

Since $c > 1$ it must be that $d \lt 11$ and since $a \gt b$ it follows that $d \gt 3$. Then by Rule 2 $d$ must be odd, otherwise all of $a,b,c$ would be odd. This leaves $d \in \{5,7,9\}$ to check by hand one by one, giving the unique solution in the end $a = 12\,,\;\;b = 8\,,\;c = 6\,,\;d = 5$.