• Status: Solved
• Priority: Medium
• Security: Public
• Views: 395

# Lucky Ticket

My girlfriend have one of those numerous strange habbits girls have.
When we buy bus tickets, she counts ticket numbers to find out if one of us got a "lucky" one.
Ticket number are all 6 digits, e.g. "ABC DEF".
If A + B + C = D + E + F, the ticket is considered "lucky".

There, I got this thought, how many "lucky" tickets could be there?
I've tried to make a simple script to perform exhaustive search, but it hanged my browser.
So I changed it a bit (introduced search "granularity") to pick and test few numbers at random, and extrapolate results back onto all possible combinations:

<SCRiPT>
s = ""; htN = 0; N = 0; g = 250
for(i = 1000000; i < 2000000; i += Math.round(g * Math.random()), N++)
if(parseInt(i.toString().substr(1,1)) +
parseInt(i.toString().substr(2,1)) +
parseInt(i.toString().substr(3,1)) ==
parseInt(i.toString().substr(4,1)) +
parseInt(i.toString().substr(5,1)) +
parseInt(i.toString().substr(6,1)) ) { htN++; s += "<BR>" +
i.toString().substr(1,1) +
i.toString().substr(2,1) +
i.toString().substr(3,1) +
i.toString().substr(4,1) +
i.toString().substr(5,1) +
i.toString().substr(6,1); }
document.write(s + "<BR>" + htN + " (" + (htN*1000000/N) + ") out of " + N + " (1000000)");
</SCRiPT>

The output of this script was:

g = 500
225 (56207.84411691232) out of 4003 (1000000)
232 (57582.5266815587) out of 4029 (1000000)
215 (54033.67680321689) out of 3979 (1000000)
225 (56334.501752628945) out of 3994 (1000000)

g = 250
439 (54663.18017681484) out of 8031 (1000000)
414 (52518.07687428644) out of 7883 (1000000)
437 (54899.497487437184) out of 7960 (1000000)
469 (58964.04324867991) out of 7954 (1000000)

so resulting probability estimation 5.5% seems to be pretty stable.

This is where I left it. Now, I want you to present exact mathematical estimation (proove, formula and the number). A non-brute-force script to produce all combinations would be nice, but not necessary (considering that I am totally out of points ;).
0
makc_the_great
1 Solution

Commented:
My brute force script says that of the 1 million possible numbers, 55252 are 'lucky.'

There are 1000 possible 3-digit numbers.  The sum of 3 digits range from 0 to 27.  A few moments in Excel gives us the following distribution:
0 Count    1
1 Count    3
2 Count    6
3 Count    10
4 Count    15
5 Count    21
6 Count    28
7 Count    36
8 Count    45
9 Count    55
10 Count    63
11 Count    69
12 Count    73
13 Count    75
14 Count    75
15 Count    73
16 Count    69
17 Count    63
18 Count    55
19 Count    45
20 Count    36
21 Count    28
22 Count    21
23 Count    15
24 Count    10
25 Count    6
26 Count    3
27 Count    1

The odds of getting a lucky '0' are (1/1000)².  The odds of getting a lucky '1' are (3/1000)².  Sum these odds together, and we get 5.5252%, which is what the brute force method suggested.
0

Commented:
There are 1000 possibilites for ABC (000 thru 999).

The sum of A+B+C must be between 0 and 27, so there are 28 possibilites.  They are not evenly distributed.

Here is a brute force solution with Excel:

0      1            1.000E-06
1      3            9.000E-06
2      6            3.600E-05
3      10            1.000E-04
4      15            2.250E-04
5      21            4.410E-04
6      28            7.840E-04
7      36            1.296E-03
8      45            2.025E-03
9      55            3.025E-03
10      63            3.969E-03
11      69            4.761E-03
12      73            5.329E-03
13      75            5.625E-03
14      75            5.625E-03
15      73            5.329E-03
16      69            4.761E-03
17      63            3.969E-03
18      55            3.025E-03
19      45            2.025E-03
20      36            1.296E-03
21      28            7.840E-04
22      21            4.410E-04
23      15            2.250E-04
24      10            1.000E-04
25      6            3.600E-05
26      3            9.000E-06
27      1            1.000E-06

1000            5.525E-02   ==>  5.525 percent

0

Commented:
>> snoyes_jw     Sorry for the crossed posts.  Long live Excel.
0

Author Commented:
hmm... I still would like some sort of formula. meantime, I've improved my script. it doesn't hang now, but is extremely slow:

<BODY ID=BID>

</BODY>

<SCRiPT>
s = ""; htN = 0; body = document.getElementById("BID");

partial = function (i)
{
sn = i.toString().substr(1,6)
if(sn.charCodeAt(0) + sn.charCodeAt(1) + sn.charCodeAt(2) ==
sn.charCodeAt(3) + sn.charCodeAt(4) + sn.charCodeAt(5))
{ htN++; s += "<BR>" + sn; }
if (i % 1000 == 0)
body.innerHTML += "<BR>" + i + "-th passed...";
if (i < 2000000) setTimeout("partial("+(i+1)+")", 1); else
body.innerHTML += s + "<BR>" + htN + " out of 1000000";
}

partial(1000000)
</SCRiPT>

I am going to run it on our PIVx2 server tommorow, just out of interest :)
0

Commented:
<SCRiPT>
var s = new Array(9*3); htN = 0;
for(n=0; n<=9*3; n+= 1){
s[n]=0;
}
for(i=1000; i<2000; i+= 1 ){
sn = i.toString().substr(1,3)
s[parseInt(i.toString().substr(1,1)) +
parseInt(i.toString().substr(2,1)) +
parseInt(i.toString().substr(3,1))] += 1;
}
for(n=0; n<=9*3; n+= 1){
htN += s[n]*s[n];
}
document.write( htN + " out of 1000000") ;

</SCRiPT>
0

Author Commented:
snoyes_jw you said "5.5252%" that yields 55,252 combinations, and d-glitch you said "5.525 percent" that yields 55,250 combinations ???

also, numbers - "A few moments in Excel gives us the following distribution" and "They are not evenly distributed. Here is a brute force solution with Excel" do not explain how did you get these numbers.
0

Author Commented:
...ah, ozo script explains.
0

Author Commented:
okay, I'd like to split points, but I cant, since there ain't enough. I think ozo said more without single word, so he gets it all.
0

Commented:
And you said:    resulting probability estimation 5.5%   which means 55,500 combinations????

My method and solution are identical to those of snoyes_jw.
I rounded my answer to four significant figures.
He gave you all five, which is certainly proper in this case.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.