# Compute average distance between numbers $0$ to $10$ [duplicate]

I'd like to calculate the average difference between two numbers, each between $0$ and $10$. I calculated this for integers and came up with an average distance of $4$.

My method: there are $10$ ways to obtain a difference of $1$, $9$ ways to obtain a difference of $2$, $3$ of $8$, $4$ of $7$, $5$ of $6$, $6$ of $5$, etc. I took the weighted average of all the possibilities and I ended up with $\frac{220}{55} = 4$.

But I actually have float values between $0$ and $10$. If I did the integer average distance correctly, is the average distance between $0$ and $10$ continuous still $4$?

• I don't think averages are well-defined across infinite sets. – Wildcard Jan 4 '17 at 1:36
• it should be 10/3 – Saketh Malyala Jan 4 '17 at 1:40
• It does not really matter to you, since you want the solution for real numbers rather than integers, but the average distance between two integers is less than 4 if the integers are chosen uniformly and independently, because there is a 1/11 probability that the difference will be zero. – David K Jan 4 '17 at 1:48
• Thanks! I've checked out link and that might solve my problem provided it works for continuous. So, if I may, can we agree that the continuous solution is equal to the discrete solution, given symmetry? – zazizoma Jan 4 '17 at 2:10

## 1 Answer

Every pair of numbers between $0$ and $10$ can be associated with a unique point $(x,y)$ in the square $[0,10] \times [0, 10]$. For such a point, the function $f(x,y)=|x-y|$ measures the difference between the two numbers. To find the average value of that function, one computes $$\frac{1}{100}\int_0^{10} \int_0^{10} |x-y| dx dy$$

The integral is the continuous analog of "summing" all of the integer values; the $100$ measures the area of the square region, which is the continuous analog of the "number" of integer values.

• Thanks! I'll play with that a bit. – zazizoma Jan 4 '17 at 2:11
• Okay, I got 3.33 for this definite integral, which is the same solution as for the discrete as given above, which was 10/3. – zazizoma Jan 4 '17 at 2:31
• Yes, that's right. See also the link in dxiv's comment under your question. – mweiss Jan 4 '17 at 2:35