In the 1982 MAA Annual High School Mathematics Examination (Problem #28), contestants were given this puzzle:
"A set of consecutive positive integers beginning with 1 is written on a blackboard. One number is erased. The average (arithmetic mean) of the remaining numbers is $35\frac{7}{17}$. What number was erased?"
Let $n$ be the number of integers originally written: $1, 2, 3, \dots, n$.
The sum of all $n$ integers is given by Gauss's triangular formula:
$$S_n = 1 + 2 + \dots + n = \frac{n(n + 1)}{2}$$
If one number $x$ (where $1 \le x \le n$) is erased, the remaining $n - 1$ numbers have sum $S_n - x$, and their average is:
$$\text{Average} = \frac{\frac{n(n + 1)}{2} - x}{n - 1} = 35\frac{7}{17} = \frac{602}{17} \approx 35.41176$$
Notice the bounds on this average:
If the smallest number ($x = 1$) is erased, the average is maximized: $\frac{n + 2}{2}$.
If the largest number ($x = n$) is erased, the average is minimized: $\frac{n}{2}$.
Therefore:
$$\frac{n}{2} \le 35\frac{7}{17} \le \frac{n + 2}{2} \implies 68.8 \le n \le 70.8$$
Since $n$ must be an integer, $n$ can only be 69 or 70. Furthermore, because $35\frac{7}{17} \times (n - 1)$ must be an integer sum, $n - 1$ must be a multiple of 17. For $n = 69$, $n - 1 = 68 = 4 \times 17$!
In this lesson, we write loops in Lua to test candidate values of $n$ and $x$, find the erased number, and explore how computers solve discrete inverse problems!
Now you try. Replace ???? with n - 1 and run the code to verify that x = 7 from a sequence of 69 numbers. Then examine Example 1 for an exact integer solver.
Type your code here:
See your results here:
Share your code
Show a friend, family member, or teacher what you've done!
Here is a share link to your code:
Need a hint?
💡 What now?
The code has ???? for the number of remaining integers after erasing one number. Replace ???? with n - 1 and click Run Code to find the erased number!
Notice how the nested loop systematically tests pairs $(n, x)$ to match the fractional average.
Check Example 1 to see how we can eliminate floating-point approximation by clearing denominators with integer arithmetic!