Solved

# Lucky Ticket

Posted on 2005-05-05

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 ;).