# Combinatorics: picking 4 numbers such that sum of 2 is equal to sum of other 2

Bus tickets in certain city contains four numbers u,v,w,x. Each of these numbers is equally likely to be any of the 10 digits 0,1,2....,9 and four numbers are chosen independently. A bus rider is said to be lucky if u+v=w+x. What proportion of riders are lucky?

• Hi Arbit, welcome to CV! Thanks for adding the self-study tag to your question. This page offers info on homework questions: stats.stackexchange.com/tags/self-study/info One of the things you should add to your question is what you've tried so far and where you get stuck (as of now, you've merely copy-pasted the question without showing an attempt at solving it) Aug 20, 2014 at 4:57
• I'll remember to do that in the future. But i was able to figure this one out! Aug 20, 2014 at 6:13

I wrote the following Java code that solves your problem:

public class Lucky{

public static void main(String []args){
int i,j,m,n;

int numOfTuples = 0;
int numOfLucky = 0;

for (i=0; i<=9;i++)
for (j=i; j<=9;j++)
for (m=j; m<=9;m++)
for (n=m; n<=9;n++)
{
numOfTuples++;
if (isLucky(i,j,m,n)) numOfLucky++;
}

System.out.println(numOfLucky + " " + numOfTuples);

}

private static boolean isLucky(int a,int b,int c,int d)
{
if (
a+b==c+d ||
a+c==b+d ||
a+d==b+c
)
return true;
else
return false;
}
}


The code requires an ordering on the numbers (u,v,w,x) - this handles duplicates like (1,2,3,4) and (2,1,3,4) (and all possible arrangements) so that they are not counted twice or more.

It answers 125 715 so the proportion of riders that are lucky is 125/715 = 17.5%

• This code is mistaken because it does not enumerate all possibilities with the correct probabilities. Brute force (such as with(expand.grid(u=0:9, v=0:9, w=0:9, x=0:9), mean(u+v==w+x)) in R) or appeal to properties of probabilities (as in the solution p <- rep(1, 10)/10; sum(convolve(p, p, type="open")^2)) reveal the correct answer is $670/10000 = 0.067$. As a reality check, a quick Normal approximation to this probability can be computed as dnorm(0, 0, sqrt(4 * (mean((0:9 - mean(0:9))^2)))), which works out to $0.0694\ldots$.
– whuber
Sep 1, 2014 at 16:07