[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Lucky Ticket

Posted on 2005-05-05
9
Medium Priority
?
392 Views
Last Modified: 2008-03-06
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
Comment
Question by:makc_the_great
9 Comments
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 13939688
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
 
LVL 27

Expert Comment

by:d-glitch
ID: 13939845
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
 
LVL 27

Expert Comment

by:d-glitch
ID: 13939905
>> snoyes_jw     Sorry for the crossed posts.  Long live Excel.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:makc_the_great
ID: 13940322
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
 
LVL 85

Accepted Solution

by:
ozo earned 120 total points
ID: 13942977
<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
 
LVL 2

Author Comment

by:makc_the_great
ID: 13942987
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
 
LVL 2

Author Comment

by:makc_the_great
ID: 13942999
...ah, ozo script explains.
0
 
LVL 2

Author Comment

by:makc_the_great
ID: 13943013
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
 
LVL 27

Expert Comment

by:d-glitch
ID: 13944485
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question