Open Side Menu Go to the Top
Register
A Simple?? Probability Calculation A Simple?? Probability Calculation

09-11-2020 , 02:35 PM
You have 10 cards, numbered 1 to 10. You deal two cards to two players. What is the probability that at least one of the players has two cards with an exact difference of 2.

Please show your work.
A Simple?? Probability Calculation Quote
09-11-2020 , 03:42 PM
An individual can get it 9 ways out of C(10,2).

P(either gets it) = 2(9/45) - P(both get it)

P(both) is more involved due to the card removal. I split it into the types of patterns the two players can combine to form. One pattern is a 4-card straight, eg. 13 + 24 = 1234. The next pattern is 1346. After that, the gap between the 2nd and 3rd number grows by 1 until the final pattern, 138T. So there are 5 patterns that aren't straights.

There are 10-4+1 = 7 straight combos.
The 1346/2457/... pattern has 10-6+1 = 5 combos
Each pattern after that has one fewer combo than the previous, so the total is 7+5+4+3+2+1 = 7+C(6,2)
= 22

There are C(10,4)*3=630 ways to deal cards to two players if we only care about the grouping of the cards.

2/5 - 22/630 = 23/63
A Simple?? Probability Calculation Quote
09-11-2020 , 05:25 PM
Quote:
Originally Posted by heehaww
An individual can get it 9 ways out of C(10,2).


2/5 - 22/630 = 23/63
Isn't it 8 ways for one individual? If so, and if the second part is not affected, the answer would be

16/45-22/630 =32.06%

I did it Pr(A)+Pr(not A)*Pr(B|not A) and got 32.6% but I could have got the second term wrong, especially when a simulation matches 32.06%.
A Simple?? Probability Calculation Quote
09-11-2020 , 05:34 PM
Whoops yes 8 ways, so 101/315 or 32.0635%

Quote:
Pr(A)+Pr(not A)*Pr(B|not A)
I felt like that would be messier. How much work was it compared to what I showed? Maybe you should paste your work since our answers still differ slightly.
A Simple?? Probability Calculation Quote
09-11-2020 , 07:35 PM
It was a lot more complicated and I'll try to figure out a way to present it compactly.

Basically I counted the number of ways A did not hit, 2 cards with a diff. of 1 or 3,or more than 3. For each case, I counted the number of ways B could hit. I then weighted each possible case by its occurrence frequency and summed up.
A Simple?? Probability Calculation Quote
09-11-2020 , 08:30 PM
I missed the part where you said a sim confirmed 32.06%. In that case, don't have to bother pasting anything unless you're curious about where your mistake was. I'm guessing it was a goofy/uninteresting mistake, the kind that happens when doing just about any long calculation.
A Simple?? Probability Calculation Quote
09-11-2020 , 09:30 PM
Okay, but you probably put too much confidence in my simulation prowess
A Simple?? Probability Calculation Quote
09-12-2020 , 07:36 AM
I went ahead and simmed it because I was curious whether it would be faster to avoid repetition by using while-loops or by shuffling a vector. In Julia:

Shuffle method:
Code:
import Random.randperm!
function onegap(n=100000000)
    hits = 0
    deck = [k for k=1:10]
    for j=1:n
        randperm!(deck)
        (abs(deck[1]-deck[2])==2 || abs(deck[3]-deck[4])==2) && (hits+=1)
    end
    return hits/n
end
While-loop method:
Code:
function onegap(n=100000000)
    hits = 0
    for j=1:n
        a = rand(1:10)
        b = rand(1:10)
        while b==a b=rand(1:10) end
        c = rand(1:10)
        while (c==a || c==b) c=rand(1:10) end
        d = rand(1:10)
        while (d==a || d==b || d==c) d=rand(1:10) end
        (abs(a-b)==2 || abs(c-d)==2) && (hits+=1)
    end
    return hits/n
end
On my machine, the first code ran in about 16 seconds whereas the 2nd took 11 seconds.

Both agree with 32.06%
A Simple?? Probability Calculation Quote
09-12-2020 , 10:21 AM
My simulation is written in VBA for Excel, which doesn't have a reputation for being a speed demon. It took about 15 seconds, but the program has options for evaluating a number of different criteria which must be lake some time, so I'm surprised it was comparable to Julia.

Obviously my coding must be superb!!!

(or else I have a faster computer or Julia itself is no speed demon OR you're a lousy coder)

Last edited by statmanhal; 09-12-2020 at 10:31 AM.
A Simple?? Probability Calculation Quote
09-12-2020 , 10:53 AM
Alright wise guy guess what, I got it down to 6sec by replacing rand(1:10) with ceil(Int64, 10*rand())

15sec for 100mm trials? When running, does it use one CPU core or automatically use multi? Does it use Mersenne Twistor like Excel, or the old flawed RNG? I remember that causing an issue for someone on here once, VBA used an inferior RNG to Excel and the flaw was big enough to throw off their sim results.
A Simple?? Probability Calculation Quote
09-12-2020 , 11:04 AM
So, my brilliant idea worked!

I got heehaw to recognize a subtle challenge to do better and better he did.
A Simple?? Probability Calculation Quote
09-12-2020 , 11:08 AM
Appeal to ego is effective on someone with a massive ego

Now 5.6 seconds by keeping everything a Float64 instead of rounding to Int64. TIL

I'm still curious about my questions though because I too would have expected Julia's margin to be wider. (Edit: maybe not, I guess it depends on whether you used a shuffle or opted to redraw until no repeats. If shuffle on a single cpu thread, then you matched Julia.)

Last edited by heehaww; 09-12-2020 at 11:19 AM.
A Simple?? Probability Calculation Quote
09-12-2020 , 12:01 PM
I used a redraw until no repeats.
A Simple?? Probability Calculation Quote
09-12-2020 , 06:21 PM
"Doing better" is in the eye of the beholder.

You are simulating 100 million times, an experiment that only has 10C2*8C2 equally likely outcomes?

Here's a horribly inefficient brute-force way to get 101/315:

Sum[If[a != b && a != c && a != d && b != c && b != d &&
c != d && (Abs[a - b] == 2 || Abs[c - d] == 2), 1, 0], {a, 1,
10}, {b, 1, 10}, {c, 1, 10}, {d, 1, 10}] /
Sum[If[a != b && a != c && a != d && b != c && b != d && c != d , 1,
0], {a, 1, 10}, {b, 1, 10}, {c, 1, 10}, {d, 1, 10}]

It can of course be made much more efficient
A Simple?? Probability Calculation Quote
09-13-2020 , 07:41 PM
Quote:
Originally Posted by Siegmund
You are simulating 100 million times, an experiment that only has 10C2*8C2 equally likely outcomes?
Good point lol. And really only half that many.
A Simple?? Probability Calculation Quote

      
m