Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Dice game... wrecking my head :)

  • 19-10-2015 10:30am
    #1
    Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭


    So here's the game:

    You roll N dice.
    I roll M dice (where M>=N).

    I win if my roll includes all of your roll.

    Example: N=4 , M=6
    You roll: 1,1,3,4
    I roll 1,1,2,3,4,6 ... I win!

    You roll 1,3,4,6
    I roll 1,1,2,3,5,6 I lose (I didn't roll at least one 4).

    Is this just M c N ? For some reason I cant get my head around this lol!

    I need a general formula because I want to have a matrix of N vs M odds.


«1

Comments

  • Registered Users, Registered Users 2 Posts: 5,063 ✭✭✭Greenmachine


    Okay couple of things.

    You are not looking to have the greatest sum from the dice?
    The winning Player appears to be player who has the highest unique value?
    Does the value need to be unique to that player?

    Say

    I being (N) roll 5, 5, 5, 5

    You roll (M) 1, 1, 3, 3, 3, 2

    You have the only 2,
    But I am I only player to have 5, no player has a 6.

    You have confused things by listing N, before M,
    I have left them as you have. Generally they are kept in alphabetical order on purpose so it is clear which values apply to which party.

    Can't help you with the maths, but wan't to clarify what you were asking. :o:o


  • Moderators, Recreation & Hobbies Moderators Posts: 4,668 Mod ✭✭✭✭Hyzepher


    I think N's roll must be a subset of Ms roll for M to win


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Yes, N's roll must be a subset of M's for M to win.

    There is no consideration of the actual values or sum there of... just pattern matching.


  • Registered Users, Registered Users 2 Posts: 5,141 ✭✭✭Yakuza


    My gut reaction is that this is a bit more subtle than [latex]M \choose N[/latex].

    Consider a concrete example:
    Rolling two dice, there are 36 possible combinations but only 21 unique combinations (I did this by hand, but verified with the method I used below)
    Rolling three dice, there are 216 possible combinations but only 56 unique combinations.

    Would then the probability of getting a match of the 21 possible 2-dice combinations from the 56 3-dice combinations be then 21/56 or 3/8?

    4 dice; 126 unique combinations
    5 dice; 252 unique combinations
    6 dice; 462 unique combinations
    7 dice; 792 unique combinations

    I can't spot a pattern in this just yet (at work so can't give it too much time!)

    How did I get the values above? I used SQL server and its set-handling capabilities.
    By creating a table with 6 rows in it (values 1-6) and then joining to this twice, three times, four times etc.

    I then took the resulting output and sorted it using two user-defined functions I googled (so that, for example, 2111, 1121, 1112 and 1211 all collapse to 1112) and took the distinct values of each.

    Sample code:
    create table #diceroll(	roll [int] NOT NULL)
    insert into #diceroll values (1)
    insert into #diceroll values (2)
    insert into #diceroll values (3)
    insert into #diceroll values (4)
    insert into #diceroll values (5)
    insert into #diceroll values (6)
    
    select distinct dbo.udf_SortString(roll) from 
    (
    select convert(char(1),d1.roll) + convert(char(1),d2.roll) + convert(char(1),d3.roll) + convert(char(1),d4.roll) + convert(char(1),d5.roll) + convert(char(1),d6.roll) + convert(char(1),d7.roll) as roll
    from #diceroll d1, #diceroll d2, #diceroll d3, #diceroll d4, #diceroll d5, #diceroll d6, #diceroll d7
    ) CombinedRolls6
    order by 1
    
    drop table #diceroll
    
    
    
    


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    While the numbers are useful there is something wrong with the logic there. If it was just as simple as 21/56 then if M was also 2 it would be 21/21 = 1... a certainty! :)

    This isnt as simple as it first seems :)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 43 ClovisI


    Not sure I understand the question.

    Is 1,2 a subset of 3,2,1?

    Assuming it isn't (i.e. that 2,1 WOULD be a subset) the answer is [latex]\frac{{{M}\choose{N}}5^{M-N}}{6^M}[/latex].


  • Registered Users, Registered Users 2 Posts: 5,141 ✭✭✭Yakuza


    DeVore wrote: »
    While the numbers are useful there is something wrong with the logic there. If it was just as simple as 21/56 then if M was also 2 it would be 21/21 = 1... a certainty! :)

    This isnt as simple as it first seems :)

    Yeah, I was a bit dubious myself that that was the answer, but lunchtime was over :)


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    ClovisI wrote: »
    Not sure I understand the question.

    Is 1,2 a subset of 3,2,1?

    Assuming it isn't (i.e. that 2,1 WOULD be a subset) the answer is [latex]\frac{{{M}\choose{N}}5^{M-N}}{6^M}[/latex].
    Yes it would be a subset. The order is irrelevant (I should have made that clear). 1,2 is covered by 3,2,1.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    I can restate the game a bit:.

    You roll N dice. (lets say in this case its 2 dice and you roll 3,4).
    I roll M dice (in this case lets say 5 dice and I roll 1,1,3,4,6).

    To win I must be able to match each of your dice results (a 3 and a 4 in this case) with two matching dice from my roll (ie: I must roll at least one 3 and one 4). The rest of my dice result are irrelevant. The order is irrelevant also (I just listed the results ascending from force of habit :) )

    In my example, I win because I can push forward a dice showing 3 to match yours and a dice showing 4 to match your other dice. I've completely matched your roll, so I win. Anything else, I lose.


  • Registered Users, Registered Users 2 Posts: 43 ClovisI


    OK I see, that complicates things. It's a nice problem.

    Is it necessary to find an exact formula? It seems unlikely that we'll find one that doesn't involve 5 or six disgusting nested sums.

    You might be able to make progress in the limit as N and M get large keeping M/N constant though; then you can approximate things as uniform distributions.

    E.g. for the simpler problem where the dice are replaced by two-sided coins, the exact form for the probability that M beats N is

    [latex]\Sigma_{n=0}^N{{N}\choose{n}}(\frac{1}{2})^N\Sigma _{m=n}^{M-N+n}{{M}\choose{m}}(\frac{1}{2})^M=(\frac{1}{2})^{M+N}\Sigma_{n=0}^N\Sigma _{m=n}^{M-N+n}{{N}\choose{n}}{{M}\choose{m}}[/latex].

    but if we let [latex]M,N\rightarrow \infty, M/N=\alpha[/latex]
    this tends to

    [latex]P(\alpha Y\geq X, \alpha(1-Y)\geq(1-X))[/latex] where X and Y are uniformly distributed in [0,1]. This actually evaluates to [latex]1-\frac{1}{\alpha}=1-\frac{N}{M}[/latex].

    *Actually the last part is wrong, will fix later I'm busy now.


  • Advertisement
  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Yeah... and I can solve this programmatically but I had been hoping for an elegant solution and I still somehow think there is one. But such a simple problem is really messes things up royally! :)


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    A friend who knows his maths has offered this as a solution:

    http://www.wolframalpha.com/input/?i=Sum%5b+Binomial%5bx+-+1%2c+n+-+1%5d+f%5en+(1+-+f)%5e(x+-+n)%2c+%7bx%2c+n%2c+m%7d%5d

    He says:
    I roll my n dice.
    You start rolling yours.

    Call it success when a roll of your dice matches my first roll. Success on your first roll happens with probability f =1/6, otherwise failure (probability 1-f), so keep going until you get a match.

    Then start rolling again until you get a match of my second roll, and so on.

    You want to find the probability of getting n successes within m rolls. The chance of getting exactly n successes in x >= m rolls *and* having success on the last roll x, is Binomial [ x - 1, n -1 ] f^n (1-f)^(x-n). Here the f^n (1-f)^(x-n) part comes from having n successes and x-n failures, and the Binomial [ x - 1, n -1 ] part comes form the fact that the first n-1 success can occur anywhere in the first x -1 rolls. So sum this up for x running from n (minimum possible) to m (number of rolls you are allowed). (Detail: the condition on the last roll being the n^th success makes this a sum over disjoint events)


  • Registered Users, Registered Users 2 Posts: 43 ClovisI


    Sounds like your friend made the same misinterpretation as me at first: he assumed that we only want "ordered" subsets.
    Based on that incorrect assumption he's right, I see now that my first answer was off.


  • Registered Users, Registered Users 2 Posts: 5,063 ✭✭✭Greenmachine


    I Don't know if this add anything or not.

    If I my two dice first I see to basic outcome. I will roll two unique values, one the same value.
    The chance of my rolling the same value twice is 1/6, and the chance of 2 unique values is 5/6.
    Do you need to test for either outcome.

    I ask because if my two dice are the same value the chance of rolling the correct value on your first roll is 1/6. You have 6 possible outcome and only 1 is favorable. Each individual roll has a 1/6 in 6 after this of achieving the required value and of course is independent of the other. Clearly if you had an unlimited number of rolls you would eventually roll the same value again.

    If both my value are unique, there are 2 values that you have the chance to match on your first, or indeed any subsequent roll, once you match, my first value, each subsequent roll will each have as you know a in 6 chance to match. Again I am sure you understand this. I am just wondering if any of the proposal you have seen have tested for both case.

    I at least am at little clearer on what your asking. The collective brains (mine excluded :pac:) can surely work it out. I heard mentions of subsets, and though I remember those, but what you have put in front of us is a lot more interesting than working out the chance of winning the lottery.

    Which has given me a though. I believe there is formula only regarding the odd for a particular type of bet you do in bookies. I don't frequent them no can't help you. Something tells me if apply the concept in inverse, you might get somewhere.

    Conceptually you for example pick 3 numbers in the lottery and place a bet on these. Your 3 numbers must be 3 of the 6 numbers drawn. In this case the pool of numbers is much larger, than in you dice game but it is a computational formulation e.g (5!/3!) but more derived. If you can work out what I am saying from my horrible explanation, you should be able to work back.

    Or not, in which case, I will leave the thread, to those who know better. :pac::pac:


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    The problem with reversing it (which was, to be fair, the first thing I thought of because its often easier), is that it pretty much becomes the same problem, just that you are going to subtract it from 1 at the end.

    ie: the problem goes from match this specific set of outcomes with M dice,
    to: match all of your M must match these OTHER outcomes and you are allowed N-1 failures to do so with repeats of N-1 non-matching numbers along the way :)

    ie: if your roll was 3,4 with 2 dice and I have 5 dice then I need to roll at least 4 from the set [1,2,5,6] along with multiples of the same one (lots of 3's say, but no fours). Its actually at least as hard to work out :)

    Its a bugger, but I think my mates way of doing it is the cleanest I've seen...


  • Registered Users, Registered Users 2 Posts: 166 ✭✭gleesonger


    This is my approach,
    let f(x) = (5/6)^x
    let g(x) = f(x) + (1-f(x)) * g(x-1)
    let g(M-N)=0 (ie recursive from M to N)
    
    Probability_M_Wins = g(M)
    

    Example of formula in Excel

    I assume that there is no double counting allowed, ie if there are two IVs rolled then M must roll at least 2 IVs.

    I am not convinced my approach works.
    Code lines up with formula (excel) for all smallish values but once I get to M=12, N=4 I am out by 3% percent, not sure yet if this is due to a coding, precision or formula error. I'm guessing the later :(.

    You can probably unwind the formula to remove the recursion. If the formula is right I might look into that.

    C# code;
    namespace ConsoleApplication1
    {
        class Hand
        {
            public const int DIE_FACE_COUNT = 6;
            public readonly int[] simulation = new int[DIE_FACE_COUNT];
    
            public bool Contains(Hand smaller_hand)
            {
                for (int i = 0; i < DIE_FACE_COUNT; i++)
                {
                    if (smaller_hand.simulation[i] > this.simulation[i])
                        return false;
                }
    
                return true;
            }
    
            public static Hand Simulate(Random rand,int num_throws)
            {
                Hand hand = new Hand();
    
                for (int i = 0; i < num_throws; i++)
                    hand.simulation[rand.Next(0, DIE_FACE_COUNT)]++;
    
                return hand;
            }
        }
    
        class Program
        {
            static void Main()
            {
                for (int i = 0; i < 3; i++)
                    RunSimulation();
    
                Console.WriteLine("Done");
                Console.ReadKey();
            }
    
            static void RunSimulation()
            {
                const int n = 3;
                const int m = 12;
                const int num_sims = 10000000;
    
                int win_count_n = 0;
                int win_count_m = 0;
    
                Random rand = new Random();
    
                for (int i = 0; i < num_sims; i++)
                {
                    bool win_m = Hand.Simulate(rand, m).Contains(Hand.Simulate(rand, n));
    
                    if (win_m)
                        win_count_m++;
                    else
                        win_count_n++;
                }
    
                double win_percent_m = ((double)win_count_m) / num_sims;
                double win_percent_n = ((double)win_count_n) / num_sims;
    
                Console.WriteLine("Win N: " + Math.Round(win_percent_n * 100, 2));
                Console.WriteLine("Win M: " + Math.Round(win_percent_m * 100, 2));
                Console.WriteLine();
            }
            
        }
    }
    


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    I've also decided to brute force this and have written a VB program I'm refining at the moment to do N = 2...9 M = 2... 9 a Million times for each iteration and store the values. I'll have an output later today!

    The formula I posted up above from a friend of mine turns out to be inaccurate because he misunderstood the game so its wrong.

    This has gone from a simple "hey, I wonder what probabilities of the dice rolls versus perils in the game Armello are" to a death march of stubbornness about this math problem. I'm going to get those probabilities if it kills me. :)

    I'll post the code here when I'm done.


  • Registered Users, Registered Users 2 Posts: 166 ✭✭gleesonger


    I realised the error in my formula, there is a lower liklihood of hitting repetitive numbers, eg @ M=2,N=2; 1,1 has a probability of 1/36 wheres 1,2 has a probability of 2/36 because 2,1 can also occur which is equal. I'm looking at something now that might work.

    What is the maximum expected size of M? Brute force could be made to be pretty quick.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Max sizes of N=6 and M=12 more or less. Computational time doesn't seem to increase particularly fast with increases in either tbh!

    Btw, wouldn't N=1 and M=1 have a probability of 1/6 (not 1/36 as you suggested?)


  • Registered Users, Registered Users 2 Posts: 166 ✭✭gleesonger


    DeVore wrote: »
    Max sizes of N=6 and M=12

    Easiest for that is to brute force the answer and store in a lookup table beside the application. I suggest going over and above the required number in case you want to increase your max value of M and also including the brute force for a fall back when the values exceed your stored results.
    DeVore wrote: »
    wouldn't N=1 and M=1 have a probability of 1/6 (not 1/36 as you suggested?)

    When I said 1,1 I was referring to the result of two die throws.

    At M=2 and N=2 if the first player throws two dies of the same value (eg 1,1 or 2,2 or .... 6,6) then the chance of the second player matching that hand is 1/36.
    However if the first player throws two dies of different values (eg 1,2 or 3,4 ,....) then the chance of the second player matching that hand is 2/36 as order doesn't matter. It think this distinction is the crux of the problem.

    To get the correct answer I suggest posting to the maths section of stackoverflow, you could get a decent answers there. If you do, post a link to your question here so I can follow. This problem has tweaked my interest!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    Are repetitions counted? For example if the opponent throws 3 1s must you also have 3 1s in your throw? Your first example seems to suggest that this is the case.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Yes, exactly...


  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    Thank you.

    Ok, Let the n,m game be the game with the first player throwing n times and the second player trying to match it with m throws.

    Consider the simplest. The 1,1 game. Here n=m=1.

    Clearly the probability of the first player winning is 5/6. (and the second player winning being 1-5/6=1/6). I think you will agree with that.

    Now we consider the 1,m game. Here the first player throws once but the second player has m throws. To win the first player must mismatch with each of the second players m throws. It is equivalent to playing the 1,1 game m times.

    So the probability of the first player winning is now (5/6)^m. The probability of the second player winning is 1-(5/6)^m. Do you agree with this so far?

    Now we generalise further. Instead of the first player throwing once he throws n times. The second player must find a match somewhere in his throws for each of the first players throws.

    So the prob of matching the first of the first players throws is the same as the 1,m game.

    1-(5/6)^m.

    Having matched the first of the first player's throws, the second player now has m-1 throws left. He must now match the second of the first player's throws with one of his remaining m-1 throws.

    The probability of finding a match on the second of the first player's throws is 1-(5/6)^(m-1). This is the equivalent of the 1,(m-1) game.

    This is repeated n times.

    So we have something like for the 3,m game:

    [latex]\displayvalue{P\left(second\right)=\left(1-\left(\frac{5}{6}\right)^{m}\right)\times\left(1-\left(\frac{5}{6}\right)^{m-1}\right)\times\left(1-\left(\frac{5}{6}\right)^{m-2}\right)}[/latex]

    For example for the the 4,6 game

    [latex]\displayvaluee{P\left(second\right)=\left(1-\left(\frac{5}{6}\right)^{6}\right)\times\left(1-\left(\frac{5}{6}\right)^{5}\right)\times\left(1-\left(\frac{5}{6}\right)^{4}\right)\times\left(1-\left(\frac{5}{6}\right)^{3}\right)=0.0867728}[/latex]
    Note the four terms. This is because n=4.

    For the 1,1 game we have

    [latex]\displayvalue{1-\left(\frac{5}{6}\right)^{1}=\frac{1}{6}}[/latex]


  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    I'm getting the same result as gleesonger with his spreadsheet. Devore, is this what you wanted? It is an iterative formula, (gleesonger's is recursive) but in both cases for any reasonable number of dice throws, the computer should be able to calculate the probabilities instantly without using brute force.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    I'm just finishing up the brute force (which is actually kinda elegant in code) and we can compare the two approaches (experimental and theoretical! FOR SCIENCE!). I'll try and paste them here today. (just sanity checking the results now).


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Ok here are my results, I *think* they are right.

    They are in the form (Rollloses is the number of times M player lost, and RollsWin is the number of times MPlayer won. Pw% is probability of a win for M in % form) I ran each [N,M] 100,000 times.

    N , M , RollLoses, RollWins, Pw%
    deleted cos they are wrong.
    


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Already I see something weird, the results for 4,4 and 4,5 are odd... how could 4,5 be less likely to win?

    This code is generic too, its the same code that worked out 3,3 and 3,4 as well as 5,5 and 5,6 and it did them correctly!

    Going to run 1000,000 times for the giggles, maybe it was just variance...


  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    Can you do very small numbers like 1,1 ; 1,2 and 2,1? These should be fairly easy to analyse.

    Lets look at 2,2. I get about 5 percent here. Can you list out the combinations you use to arrive at 20%. Perhaps your calculation of percentage is wrong. 20 is 1/5 of 100. 5 is one twentieth of 100.


  • Closed Accounts Posts: 13,404 ✭✭✭✭sKeith


    Formula to calculate PW% = RollsWins/1000


  • Advertisement
  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    If we work out 2,2 by hand...

    Lets presume that the N dice are different (we'll add in the chance of them being the same later). So its a 5/6 chance that they are different.
    The 2 M dice must both match one of the N dice. The first dice from M has a 2/6 chance of matching the second has a 1/6 chance of matching so combined they have a 2/36 chance or 1/18.

    If the two N dice DONT match then the M dice have a 1/36 chance of matching.

    so the odds are (5/6 * 1/18 ) + (1/6 * 1/36)

    This gives 11/216 or .0506 or about 5.06%


    1,1 is 1/6 or 16.66%

    1,2 is 1- (5/6*5/6) .... ie the inverse of missing with both of the M dice.
    Which is 1 - 25/36
    which is 11/36 or 30.5%


    2,1 is trivially 0. You cant ever win with fewer dice than you need to match.




    I've deleted my results because I found some sloppy array index handling between procedures, running them again now.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Dlouth, I think you are right... I'm going to fix the bugs in my code and test to see if it matches your results.
    I'm basically just geeking out OCD-like on this now because , I dunno... reasons :)


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    Ok, I've basically proven that MS cant do random.

    I thought I was chasing bugs in my code but I just couldn't see any. Eventually I forced my program to just do 1,1 and hand checked it. It was consistently wrong, it produces % wins of about 18% over 10,000 runs. That's waaaay off on that number of iterations.

    So I had it print out the actual results, line at a time and checked them and they are all correctly identified. Analysing this gives this distribution of winning pairs:

    1s 301
    2's 293
    3's 297
    4's 313
    5's 297
    6's 305

    Seems ok... there isnt a huge bias towards any given number in any of the rolls either... but still, the number of matches considerably exceeds the expected number. ie: we should see 1667 matches, but we see 1807 instead...

    Turns out, even using the new seed generator of Randomize()... the random function in VB has some issues of producing the same number in a row... hence the slightly higher match rate but the roughly correct distribution of numbers...

    Now I have to go write my own randomiser :)


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    I'm nothing if not persistent.

    So, I wrote my own randomiser and hey presto... it works. The results I got for small number dice are:

    N, M, Losses, Wins, % Win for M
     1 ,  1 ,  833268 ,  166732 ,  16.6732%
     1 ,  2 ,  694939 ,  305061 ,  30.5061%
     1 ,  3 ,  578077 ,  421923 ,  42.1923%
     2 ,  2 ,  948987 ,  51013 ,  5.1013%
     2 ,  3 ,  871958 ,  128042 ,  12.8042%
     3 ,  3 ,  978773 ,  21227 ,  2.1227%
    

    Those look good so I'll run the bigger numbers too.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    The results for the bigger numbers are:

    N, M, Losses, Wins, % Win for M
     1 ,  1 ,  833467 ,  166533 ,  16.6533%
     1 ,  2 ,  693709 ,  306291 ,  30.6291%
     1 ,  3 ,  578424 ,  421576 ,  42.1576%
     1 ,  4 ,  481961 ,  518039 ,  51.8039%
     1 ,  5 ,  401641 ,  598359 ,  59.8359%
     1 ,  6 ,  335149 ,  664851 ,  66.4851%
     1 ,  7 ,  278186 ,  721814 ,  72.1814%
     1 ,  8 ,  233057 ,  766943 ,  76.6943%
     1 ,  9 ,  193878 ,  806122 ,  80.6122%
     2 ,  2 ,  949424 ,  50576 ,  5.0576%
     2 ,  3 ,  871883 ,  128117 ,  12.8117%
     2 ,  4 ,  783843 ,  216157 ,  21.6157%
     2 ,  5 ,  694529 ,  305471 ,  30.5471%
     2 ,  6 ,  607487 ,  392513 ,  39.2513%
     2 ,  7 ,  527653 ,  472347 ,  47.2347%
     2 ,  8 ,  456209 ,  543791 ,  54.3791%
     2 ,  9 ,  391299 ,  608701 ,  60.8701%
     3 ,  3 ,  978931 ,  21069 ,  2.1069%
     3 ,  4 ,  934458 ,  65542 ,  6.5542%
     3 ,  5 ,  873204 ,  126796 ,  12.6796%
     3 ,  6 ,  802380 ,  197620 ,  19.762%
     3 ,  7 ,  725325 ,  274675 ,  27.4675%
     3 ,  8 ,  647969 ,  352031 ,  35.2031%
     3 ,  9 ,  574071 ,  425929 ,  42.5929%
     4 ,  4 ,  989245 ,  10755 ,  1.0755%
     4 ,  5 ,  961739 ,  38261 ,  3.8261%
     4 ,  6 ,  918679 ,  81321 ,  8.1321%
     4 ,  7 ,  862477 ,  137523 ,  13.7523%
     4 ,  8 ,  797529 ,  202471 ,  20.2471%
     4 ,  9 ,  729780 ,  270220 ,  27.022%
     5 ,  5 ,  993636 ,  6364 ,  .6364%
     5 ,  6 ,  975575 ,  24425 ,  2.4425%
     5 ,  7 ,  944303 ,  55697 ,  5.5697%
     5 ,  8 ,  899891 ,  100109 ,  10.0109%
     5 ,  9 ,  845908 ,  154092 ,  15.4092%
     6 ,  6 ,  995890 ,  4110 ,  .411%
     6 ,  7 ,  983482 ,  16518 ,  1.6518%
     6 ,  8 ,  959584 ,  40416 ,  4.0416%
     6 ,  9 ,  924301 ,  75699 ,  7.5699%
    


  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    That looks more like it.

    Here's a small function in some form of basic to calculate it.
    Function Prb(n, m)
    	Prb=1
    	For i = 0 to n-1
    		Prb = Prb * ( 1 - (5/6)^(m-i) )
    	Next i
    End Function
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 338 ✭✭ray giraffe


    I have a formula for (2,M) which agrees with DeVore's results.
    I'm confident I can finish a formula for (3,M) with a bit more work but (4,M) is beyond me.

    I have a little proof that the probability that N throws of a coin match the next N throws in any order approaches (1/sqrt(Pi*N)) as N becomes large.


    The most useful information for DeVore right now is probably that the 95% margin of error is approximately 1/sqrt(n).

    In other words with a million runs, 95% of the simulation probabilities are correct within 1/1000=0.001=0.1%

    For example, with (1,2) the exact answer is 30.55555% and the simulation answer is 30.6291% which is within 0.1%.

    With the formula we can see that if he increases his simulation to 4 millions runs each, his margin of error drops to 0.05%.


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    I ran 1,1 and 1,2 up to 4M iterations each and the results are:
     1 ,  1 ,  3332320 ,  667680 ,  16.692%
     1 ,  2 ,  2777824 ,  1222176 ,  30.5544%
    

    So, it seems like your info is accurate!


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    dlouth15 wrote: »
    That looks more like it.

    Here's a small function in some form of basic to calculate it.
    Function Prb(n, m)
    	Prb=1
    	For i = 0 to n-1
    		Prb = Prb * ( 1 - (5/6)^(m-i) )
    	Next i
    End Function
    
    When I run this over N=1..6 and M=N..9 I get this:
    1	1	16.67
    1	2	30.56
    1	3	42.13
    1	4	51.77
    1	5	59.81
    1	6	66.51
    1	7	72.09
    1	8	76.74
    1	9	80.62
    
    2	2	5.09
    2	3	12.87
    2	4	21.81
    2	5	30.97
    2	6	39.78
    2	7	47.95
    2	8	55.33
    2	9	61.87
    
    3	3	2.15
    3	4	6.66
    3	5	13.05
    3	6	20.60
    3	7	28.68
    3	8	36.80
    3	9	44.60
    
    4	4	1.11
    4	5	3.99
    4	6	8.68
    4	7	14.85
    4	8	22.01
    4	9	29.67
    
    5	5	0.66
    5	6	2.65
    5	7	6.26
    5	8	11.40
    5	9	17.74
    
    6	6	0.44
    6	7	1.91
    6	8	4.80
    6	9	9.19
    


  • Registered Users, Registered Users 2 Posts: 338 ✭✭ray giraffe


    Formulas:

    (1,m) is
    1-(5/6)^m

    (2,m) is
    (1/6)*(1-(5/6)^m-m*(5/6)^(m-1)*(1/6))
    +(5/6)*(1-2*(5/6)^m+(4/6)^m)

    (3,m) is
    (1/6)^2*(1-(5/6)^m-m*(5/6)^(m-1)*(1/6)-COMBIN(m,2)*(5/6)^(m-2)*(1/6)^2)
    +(15/36)*(1-2*(5/6)^m-m*(5/6)^(m-1)*(1/6)+(5/6)^m*((4/5)^m+m*(4/5)^(m-1)*(1/5)))
    +(5/6)*(4/6)*(1-3*(5/6)^m+3*(4/6)^m-(3/6)^m)


    [Aside:

    The pattern in the number of terms is the number of partitions of an integer n: 1,2,3,5,7,11 etc.
    http://oeis.org/A000041

    So (4,m) will have 5 terms (of which only 2 are doable).

    End Aside
    ]



    Here are the exact answers for (1,m) , (2,m) and (3,m) in % to 3 decimal places

    16.667%
    30.556% 5.093%
    42.130% 12.809% 2.135%
    51.775% 21.618% 6.539%
    59.812% 30.598% 12.664%
    66.510% 39.220% 19.835%
    72.092% 47.200% 27.465%
    76.743% 54.412% 35.114%
    80.619% 60.822% 42.480%

    along with the errors in DeVore's simulation

    -0.013% 0.000%
    0.074% -0.035% 0.000%
    0.028% 0.003% -0.028%
    0.029% -0.002% 0.015%
    0.024% -0.051% 0.016%
    -0.025% 0.031% -0.073%
    0.090% 0.034% 0.003%
    -0.049% -0.033% 0.089%
    -0.007% 0.048% 0.113%

    And of course 95% of those are within 0.1%, as predicted :)


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    It seems that just like GleeSonger ... the brute force diverges from the formula once N goes over 3. I have a suspicion there is something lurking in the larger numbers of dice that make things a bit more complex for the formula, but I cant rule out errors in the code of course. The accuracy at the lower numbers makes me doubt the code slightly less as it doesn't care how many dice there are, it either matches or it doesn't.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    Formulas:

    (1,m) is
    1-(5/6)^m

    (2,m) is
    (1/6)*(1-(5/6)^m-m*(5/6)^(m-1)*(1/6))
    +(5/6)*(1-2*(5/6)^m+(4/6)^m)

    (3,m) is
    (1/6)^2*(1-(5/6)^m-m*(5/6)^(m-1)*(1/6)-COMBIN(m,2)*(5/6)^(m-2)*(1/6)^2)
    +(15/36)*(1-2*(5/6)^m-m*(5/6)^(m-1)*(1/6)+(5/6)^m*((4/5)^m+m*(4/5)^(m-1)*(1/5)))
    +(5/6)*(4/6)*(1-3*(5/6)^m+3*(4/6)^m-(3/6)^m)
    Ray, How did you arrive at those?


  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    I did a simulation against Ray's formulas and got the following errors:
     0.001%
    -0.001%  0.001%
     0.000% -0.001% -0.001%
     0.002%  0.001%  0.000%
     0.000% -0.001%  0.000%
     0.001% -0.002%  0.001%
    -0.001% -0.004%  0.000%
     0.000% -0.002%  0.000%
     0.000% -0.002% -0.004%
    

    Which is very close indeed. Well done Ray.


  • Registered Users, Registered Users 2 Posts: 338 ✭✭ray giraffe


    dlouth15 wrote: »
    Ray, How did you arrive at those?
    (2,m) first:

    P(player 2 wins and player 1 has equal dice)
    +
    P(player 2 wins and player 1 has different dice)
    =
    P(2 throws are equal, call the value x)*P(next m throws have at least 2 x's (using Binomial Distribution))
    +
    P(2 throws are different, call the values x and y)*P(next m throws have at least 1 x and at least 1 y (using Inclusion-Exclusion Principle))
    =
    (1/6) * (1-(5/6)^m-m*(5/6)^(m-1)*(1/6))
    +
    (5/6) * (1-2*(5/6)^m+(4/6)^m)



    Now look at (3,m):

    P(3 throws all equal to x)*P(next m throws have at least 3 of x)
    +
    P(3 throws have 2 equal to one value x and 1 equal to a different value y)*P(next m throws have at least 2 of x and 1 y)
    +
    P(3 throws are all different and equal to x,y and z)*P(next m throws have at least 1 of x,y and z)
    =
    (1/6)^2 * (1-(5/6)^m-m*(5/6)^(m-1)*(1/6)-COMBIN(m,2)*(5/6)^(m-2)*(1/6)^2)
    +
    (15/36) * (1-2*(5/6)^m-m*(5/6)^(m-1)*(1/6)+(5/6)^m*((4/5)^m+m*(4/5)^(m-1)*(1/5)))
    +
    (5/6)*(4/6) * (1-3*(5/6)^m+3*(4/6)^m-(3/6)^m)


    There may be a much less laborious way to calculate these using generating functions possibly


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    I think we can safely say that there is no elegant general solution (or at least none that we can find!) which is curious considering how simple a problem it is to state. I suppose its like Einstein said, when seeking the truth leave elegance to the tailor :)


  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    If N is something like 5 then its going to get very complicated. We'll have to consider variations like xxxx,y, xxx,y,z and y,y,x,x,x etc


  • Registered Users, Registered Users 2 Posts: 5,141 ✭✭✭Yakuza


    I'm going to have a brute-force bash at this over the bank holiday weekend.
    This is how I'm going to restate the problem, holler if I've missed something:

    In my previous post, I worked out how many unique combinations there were of N dice (so 252 in the case of 5).

    You roll 5 dice.

    So if I'm going to roll 5 dice, then there is a 1 in 252 chance of me getting the same distinct set of rolls as you.
    If I roll 6 dice, there are 462 unique combinations, 6 of these are going to be valid super sets of your roll (your roll plus 1 or 2 or 3 or 4 or 5 or 6), so my probability should be 6 / 462.

    If I roll 7 dice, there are 792 unique combinations, 36 of which are going to be valid super sets of the original roll (the original roll and 1,1....6,6), so the probability should be 36/792.

    My conjecture is that the probability is 6^(M-N) /(#unique rolls of M dice (which I've yet to find a neat formula for))

    I'll get my C# simulation head on over the weekend and see if expectation matches reality :)


  • Registered Users, Registered Users 2 Posts: 338 ✭✭ray giraffe


    Stop the presses!!

    Henry on stackexchange got a recursive formula!!

    It appears to agree with our results, but it's way better :D

    http://math.stackexchange.com/questions/1493150/probability-n-dice-results-are-subset-of-m-dice-results


  • Registered Users, Registered Users 2 Posts: 1,595 ✭✭✭MathsManiac


    Yakuza wrote: »
    I'm going to have a brute-force bash at this over the bank holiday weekend.
    This is how I'm going to restate the problem, holler if I've missed something:

    In my previous post, I worked out how many unique combinations there were of N dice (so 252 in the case of 5).

    You roll 5 dice.

    So if I'm going to roll 5 dice, then there is a 1 in 252 chance of me getting the same distinct set of rolls as you.
    If I roll 6 dice, there are 462 unique combinations, 6 of these are going to be valid super sets of your roll (your roll plus 1 or 2 or 3 or 4 or 5 or 6), so my probability should be 6 / 462.

    If I roll 7 dice, there are 792 unique combinations, 36 of which are going to be valid super sets of the original roll (the original roll and 1,1....6,6), so the probability should be 36/792.

    My conjecture is that the probability is 6^(M-N) /(#unique rolls of M dice (which I've yet to find a neat formula for))

    I'll get my C# simulation head on over the weekend and see if expectation matches reality :)

    In the sentence that I've highlighted in bold above, you have assumed that these 252 unique combinations are equiprobable, but they are not, since the number of non-unique combinations contributing to each unique combination varies. Similarly later with your 792 combinations, etc.


  • Registered Users, Registered Users 2 Posts: 1,169 ✭✭✭dlouth15


    Ran Henry from StackExchange's numbers against the simulation and got the following errors for the simulation.
    -0.001%
     0.000%  0.001%
     0.000%  0.000%  0.000%
     0.002% -0.003%  0.001%  0.000%
     0.002% -0.001% -0.001%  0.000%  0.000%
     0.002%  0.001% -0.002%  0.001%  0.000%  0.000%
    

    The R code he supplies runs instantly.


  • Registered Users, Registered Users 2 Posts: 5,141 ✭✭✭Yakuza


    In the sentence that I've highlighted in bold above, you have assumed that these 252 unique combinations are equiprobable, but they are not, since the number of non-unique combinations contributing to each unique combination varies. Similarly later with your 792 combinations, etc.

    D'oh, I was taking an a posteriori view I guess. I'm going to get cracking on some simulations later anyway. I'm teaching myself R so the code linked above looks like a good way to get started!


  • Advertisement
Advertisement